简体   繁体   English

NODE_PATH无法识别

[英]NODE_PATH not recognized

Here is my package.json script: 这是我的package.json脚本:

"scripts": {
    "start": "NODE_PATH=$NODE_PATH:./shared node",
    "dev": "npm run start & webpack-dev-server --progress --color"
  },

When I run npm start in Windows 8 it shows the below error: 当我在Windows 8中运行npm start ,它显示以下错误:

node_path is not recognized as a internal or external command, operable program or batch file node_path不被识别为内部或外部命令,可操作程序或批处理文件

I had the same problem when I wanted to set the environment variable in a browserify script: 当我想在browserify脚本中设置环境变量时,我遇到了同样的问题:

"scripts": {
  "build:symlinked": "NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}

To be able to use linked node modules that are requiring peer-dependencies. 能够使用需要对等依赖性的链接节点模块。

As mentioned above, you can try to set the environment variable manually or by script where it seems you have to use different commands depending on what command line tool you use. 如上所述,您可以尝试手动或通过脚本设置环境变量,根据您使用的命令行工具,您似乎必须使用不同的命令。

For not having to do this every time, I found that npm package: cross-env . 为了不必每次都这样做,我发现npm包: cross-env

By installing it and applying the script like this 通过安装它并应用这样的脚本

"scripts": {
  "build:symlinked": "cross-env NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}

I was able to solve that problem. 我能够解决这个问题。 This is mainly useful, if you work in a team with mixed MAC/Linux and Windows users, so you don't have to to take care about applying the Environment variables in such scripts anymore. 如果您在具有混合MAC / Linux和Windows用户的团队中工作,这非常有用,因此您不必再关注在此类脚本中应用环境变量。

You don't need to define environment variable in package.json just use this 你不需要在package.json中定义环境变量就可以使用它

{
 "scripts" : "node server.js"
}

or define what you want, here is the reference link. 或者定义你想要的, 这里是参考链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM