如何更改 npm 中的默认 package.json 位置?
How to change the default package.json location in npm?
我有一个TestCafe 测试项目。
这是 package.json
的“脚本”部分:
"scripts": {
"test": "testcafe chrome tests"
}
当我尝试 运行 npm 脚本时,这是我得到的:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test'
1 verbose cli ]
2 info using npm@6.13.1
3 info using node@v13.3.0
4 verbose stack Error: ENOENT: no such file or directory, open 'E:\package.json'
5 verbose cwd E:\
6 verbose Windows_NT 10.0.18362
7 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "test"
8 verbose node v13.3.0
9 verbose npm v6.13.1
10 error code ENOENT
11 error syscall open
12 error path E:\package.json
13 error errno -4058
14 error enoent ENOENT: no such file or directory, open 'E:\package.json'
15 error enoent This is related to npm not being able to find a file.
16 verbose exit [ -4058, true ]
所以,它抱怨找不到 E:\package.json
这是真的,因为我的项目在 E:\projectName\
.
如何让 npm 在 E:\projectName\package.json
中查找 package.json
?怎么默认不在项目文件夹里找呢?
您可以使用 --prefix
选项。
你的情况:
$ npm --prefix E:\projectName\ ...
这是我的错误。
我用 npm test
而不是 npm run test
来启动脚本。现在可以使用了。
我有一个TestCafe 测试项目。
这是 package.json
的“脚本”部分:
"scripts": {
"test": "testcafe chrome tests"
}
当我尝试 运行 npm 脚本时,这是我得到的:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test'
1 verbose cli ]
2 info using npm@6.13.1
3 info using node@v13.3.0
4 verbose stack Error: ENOENT: no such file or directory, open 'E:\package.json'
5 verbose cwd E:\
6 verbose Windows_NT 10.0.18362
7 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "test"
8 verbose node v13.3.0
9 verbose npm v6.13.1
10 error code ENOENT
11 error syscall open
12 error path E:\package.json
13 error errno -4058
14 error enoent ENOENT: no such file or directory, open 'E:\package.json'
15 error enoent This is related to npm not being able to find a file.
16 verbose exit [ -4058, true ]
所以,它抱怨找不到 E:\package.json
这是真的,因为我的项目在 E:\projectName\
.
如何让 npm 在 E:\projectName\package.json
中查找 package.json
?怎么默认不在项目文件夹里找呢?
您可以使用 --prefix
选项。
你的情况:
$ npm --prefix E:\projectName\ ...
这是我的错误。
我用 npm test
而不是 npm run test
来启动脚本。现在可以使用了。