I am new to React-Native and I wanted to install yarn
the command below is the error i received after initiaing yarn start
i also included the version of the npm and nodejs that i installed
PS E:\Native\confusion> node -v
v12.18.1
PS E:\Native\confusion> npm -v
6.14.5
PS E:\Native\confusion> yarn -v
1.22.4
PS E:\Native\confusion> yarn start
yarn run v1.22.4
error Command "start" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
And right here is my package.json file
{
"name": "confusion",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "2.0.1"
}
}
The problem is, that inside your package.json there is nothing defined for a start command. In order to fix it, you have to create a new json-node like this and fill it with whatever command you want the start script to execute:
{
"name": "confusion",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "COMMAND WHICH SHOULD GET EXECUTED GOES HERE"
}
"devDependencies": {
"react-native-scripts": "2.0.1"
}
}
After you've defined this, you can execute yarn start and it will run your command.
Related
I have created below simple Dockerfile:
FROM node:16.7.0
WORKDIR /app
COPY . .
RUN npm install
# ENTRYPOINT [ "npm" ]
CMD ["sh", "-c", "tail -f /dev/null"]
I have added a cmd line with "tail -f /dev/null" to check exactly what's the issue if I issue npm test inside the container.
As soon as I run npm test inside the container --> It throws me below error
# npm test
> docker-jest#1.0.0 test
> jest --verbose
sh: 1: jest: not found
my package.json
{
"name": "docker-jest",
"version": "1.0.0",
"description": "Package for Jest",
"scripts": {
"test": "jest --verbose"
},
"Dependencies": {
"#babel/node": "*",
"#babel/core": "*",
"#babel/preset-env": "*",
"babel-jest": "*",
"jest": "*"
},
"license": "ISC"
}
sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
sum.test.js
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Even if I disable CMD and enable ENTRYPOINT and after the build, if I issue:
docker run -it <imagename> test
It throws me the same error, I see the npm install is installing but can't find the jest # /usr/local/lib/node_modules/ as I see the node modules are deployed in location/usr/local/lib/node_modules/ inside the container, and if I issue jest it says jest not found. If I, run the same without the container it works fine. I mean just in the command line after running npm install and then npm run test.
Can anyone assist me with why I'm getting this error and how to fix it?
-----------UPDATE-------------
Found the fix, it was because of my corrupted package-lock file. When I tested in local without the docker, I somehow corrupted the lock file, and later stage when I build and try to run using docker, the corrupted lock file was causing a whole lot of issues. So I deleted it and again ran thru docker...It's working as expected.
I had the same issue and the fix for me was running npm install -g jest (or yarn global add jest).
To add this to your package.json do the following:
"scripts: {
"test": "npm install -g jest && jest --verbose"
},
I'm struggling with multiple npm packages in a root git repository with custom dev scripts to handle launch, compile, build and so on. Now I came across npm workspaces and wanted to use this stunning new feature in my following project structure but I can't get it to work:
projectx (root)
- package.json
- apps
-- backend
-- src
-- package.json (name: #projectx/backend, scripts: "dev":"ts-node or whatever")
-- common
-- src
-- package.json (name: #projectx/common)
-- frontend
-- src
-- package.json (name: #projectx/frontend, scripts: "dev":"webpack")
My root package.json contains:
{
"name": "packagex",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": "true",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"back:dev": "npm workspace #projectx/backend dev",
"front:dev": "npm workspace #projectx/frontend dev",
"dev": "run-p back:dev front:dev"
},
"workspaces": [
"apps/*"
],
"repository": {
"type": "git",
"url": "git_url"
},
"author": "me",
"license": "ISC",
"devDependencies": {
"npm-run-all": "^4.1.5"
}
}
And now I want to start backend and frontend with npm-run-all and the command on root: npm run dev which results in:
And I also want to share the common package with backend and frontend, which should be possible in this case. Maybe anobody else is facing the same problem or has some ideas what I am doing wrong here.
npm#7.7.0 added a way to call scripts from child packages/workspaces, here are some examples based on your original:
Running a script named "dev" in all workspaces located under apps/backend:
npm run dev -w apps/backend
Running a script named "dev" in all workspaces:
npm run dev --ws
Running a script named "dev" in a package named #projectx/frontend:
npm run dev -w #projectx/frontend
More info:
Related CHANGELOG entry: https://github.com/npm/cli/releases/tag/v7.7.0
Docs: https://docs.npmjs.com/cli/v7/commands/npm-run-script#workspaces-support
Blog post: https://dev.to/ruyadorno/npm-workspaces-npm-run-and-exec-1lg0
Your "workspaces" property in package.json looks right. I'm using NPM Workspaces and it's working well, but it's still missing a lot of features so you need to wire things up yourself. I also don't think npm worksace is a command (but maybe for the future?), so here's a checklist to get it to work:
Make sure you're using Node 15+ and NPM 7+
Set all package.json to "private": true,
Delete all package-lock.json inside of your project, go to the root, then npm install. It should generate one root level package-lock.json that contains all dependencies for your workspaces
Since you're using npm-run-all, add this to your scripts:
"scripts": {
"back:dev": "cd apps/backend && npm run dev",
"front:dev": "cd apps/fontend && npm run dev",
"dev": "npm-run-all build --parallel back:dev front:dev"
}
Then start it with npm run dev.
Note, you may want to consider using start scripts instead of dev to shorten the command you need to type (e.g. npm start instead of npm run dev), but npm run dev will still be fine.
In root package.json you can also add short name for each package:
"scripts": {
"api": "npm --workspace=#app/api run",
}
#app/api is a name in package.json
And run scripts in ./packages/api folder from root like so:
npm run api lint
npm run api dev
I think you wish to:
keep scripts and dependencies separate (thus the 4 package.json files), for ease of maintenance
May I suggest a work-around without workspaces that might do what you're after:
{
...
"scripts": {
"//back:dev": "npm workspace #projectx/backend dev",
"back:dev": "npm --prefix apps/backend dev",
"//front:dev": "npm workspace #projectx/frontend dev",
"front:dev": "npm --prefix apps/frontend dev",
"dev": "run-p back:dev front:dev"
},
"//workspaces": [
"apps/*"
],
"devDependencies": {
"#local/back": "file:apps/backend",
"#local/front": "file:apps/frontend",
"npm-run-all": "^4.1.5"
}
}
The npm --prefix runs npm scripts in another folder than the current one.
The #local/back dependencies are not necessary for that, but I've found such useful if eg. a package depends on another. You might use that trick to reach for the common by:
"dependencies": {
"#local/common": "file:../common"
}
I wished a week ago that workspaces would offer a better solution, but didn't find any benefit over the above mechanisms.
I would also like workspaces to:
only expose those files in the files entry of the particular package.json (now, all are shown)
only allow import to paths in the exports of the particular package.json, if it has one
See
NPM Workspaces monorepo - share local package's distribution folder as root instead of the entire source files
I looked at and executed almost every single answer on this post:
The CLI moved into a separate package: webpack-cli
It has not helped.
Allow me to present my case:
So I have developed a container folder, a separate application where I ran npm init -y and then installed the following:
npm install html-webpack-plugin#4.5.0 nodemon webpack#5.3.2 webpack-cli#4.1.0 webpack-dev-server#3.11.0
Then I went into my package.json file and added the start script:
{
"name": "container",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack serve"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"html-webpack-plugin": "^4.5.0",
"nodemon": "^2.0.6",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.11.0"
}
}
When I go to terminal and run npm start, this is why I get every single time:
➜ container npm start
> container#1.0.0 start /Users/luiscortes/Projects/ecommRS/container
> webpack serve
[webpack-cli] The command moved into a separate package: #webpack-cli/serve
? Would you like to install #webpack-cli/serve? (That will run npm install -D #webpack-cli/serve) (Y/n) › true
And yes even if I choose Y or true and it runs its npm install -D #webpack-cli/serve, when I go back to running npm start it just gives me the same error over and over again.
Apparently, this is an issue with webpack-cli#4.1.0. I upgraded to webpack-cli#4.2.0 and now it works.
I want to run another command after running a Node.js server from a shell script on an Ubuntu box, but the second command never launch.
node server.js
xdg-open index.html
How can i fix it?
You can add into start in package.json >>
{
"name": "example",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node server.js && xdg-open index.html"
},
"dependencies": {
},
"devDependencies": {
}
}
and run with npm start
see: npm script
I published a simple package to npm and it's not working properly when installed. The package.json is as follows
{
"name": "test-package-hello",
"version": "1.0.4",
"description": "This is a test package",
"main": "index.js",
"bin": {
"hello": "index.js"
},
"scripts": {
"test": "exit 0"
},
"author": "Jeril Sebastian",
"license": "MIT",
"dependencies": {
"chalk": "^2.1.0"
}
}
I published the package using npm publish and it gets published successfully. Then I install it using npm install -g test-package-hello and it gets installed successfully.
But when I try to run the program using hello, it gives the error
/home/jeril/.nvm/versions/node/v6.11.3/bin/hello: line 1: syntax error near unexpected token `('
Apparently it's trying to run index.js as a bash script. When I examined other files in /home/jeril/.nvm/versions/node/v6.11.3/bin/, all of them have the this line on top
#!/usr/bin/env node
Where as my package's index.js doesn't have it on top.
What am i missing?
Find the source here and the published package here