admin管理员组文章数量:1410697
Let's for the sake of simplicity, say that I have a folder structure like so:
root
|-build
|-package.json
|-src
|-foo
|-foo.csproj
|-foo.cs
|-bar.cs
|-bin
|-...
|-foo.sln
Let us then say that I change the current directory to root\src\foo\bin
and execute any npm
mand, say for example the npm install
mand like so:
C:\root\src\foo\bin> npm install
We will observe that npm will start looking for the package.json
file within the current directory, and since it won't find it, will report an error like so:
npm ERR! path C:\root\src\foo\bin\package.json
npm ERR! code ENOENT
1> npm ERR! errno -4058
1> npm ERR! syscall open
1> npm ERR! enoent ENOENT: no such file or directory, open 'C:\root\src\foo\bin\package.json'
1> npm ERR! enoent This is related to npm not being able to find a file.
1> npm ERR! enoent
In this case, supposing I had a limitation that I had to execute all mands from within the root\src\foo\bin\
folder, how would I tell npm to look for the package.json
file that's in the root\build\
folder?
Let's for the sake of simplicity, say that I have a folder structure like so:
root
|-build
|-package.json
|-src
|-foo
|-foo.csproj
|-foo.cs
|-bar.cs
|-bin
|-...
|-foo.sln
Let us then say that I change the current directory to root\src\foo\bin
and execute any npm
mand, say for example the npm install
mand like so:
C:\root\src\foo\bin> npm install
We will observe that npm will start looking for the package.json
file within the current directory, and since it won't find it, will report an error like so:
npm ERR! path C:\root\src\foo\bin\package.json
npm ERR! code ENOENT
1> npm ERR! errno -4058
1> npm ERR! syscall open
1> npm ERR! enoent ENOENT: no such file or directory, open 'C:\root\src\foo\bin\package.json'
1> npm ERR! enoent This is related to npm not being able to find a file.
1> npm ERR! enoent
In this case, supposing I had a limitation that I had to execute all mands from within the root\src\foo\bin\
folder, how would I tell npm to look for the package.json
file that's in the root\build\
folder?
-
npm start --prefix 'path/to/your/package.json'
– Helping hand Commented Feb 14, 2019 at 5:55 -
Thank you. It appears as though you don't need the file name; just the folder name will do. Supplying the file name
package.json
will produce an error. – Water Cooler v2 Commented Feb 14, 2019 at 6:10 - 1 oh yeah, what I meant was the path to package.json file only. Anyways glad it worked. – Helping hand Commented Feb 14, 2019 at 11:10
2 Answers
Reset to default 4Just to ensure i understood your question right, you are in root directory and package.json
is in build sub-directory and you want to install packages from root directory, right? if so
You can give npm install <folder_path>
so in your case from root you can give npm install build/
Athough HelpingHand in the ments section to the question, and pavan skipo in the answers have provided the correct answers, I am writing this answer to consolidate what knowledge I have acquired about solving this issue as I got the answer to this question by searching some more soon after having posted this question.
To run the npm install mand and specify a path to the package.json file:
$ npm install <folder_path>
$ npm install "..\..\..\build\"
To run any other npm mand, for example an npm script and specify a path to the package.json file:
$ npm --prefix <folder_path> run <script_name>
For e.g if the package.json
had a script named build
, the mand would be:
$ npm --prefix "..\..\..\build" run build
Note that:
The trailing slash
\
(or\
) after the folder name is optional. So..\..\..\build\
is the same as../../../build/
, which is the same as..\..\..\build
.<folder_path>
is the path of the folder that contains thepackage.json
that you want npm to look for.
本文标签: javascriptTell npm to look for the packagejson in a specific folderStack Overflow
版权声明:本文标题:javascript - Tell npm to look for the package.json in a specific folder - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745041187a2639083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论