简体   繁体   English

`npm build` 不运行 package.json 中名为“build”的脚本

[英]`npm build` doesn't run the script named “build” in package.json

For a new module I'm trying to use npm build without gulp / Grunt / other specialised build tools.对于一个新模块,我尝试使用npm build而没有 gulp / Grunt / 其他专门的构建工具。

"scripts": {
  "build": "node build.js"
},

My build.js is simply我的 build.js 很简单

console.log('Hello')

However, running然而,运行

npm build

Simply exits without printing anything, with a status of 0.直接退出而不打印任何内容,状态为 0。

Running:跑步:

npm install

Also does all the normal things, but does not run build.js either.也做所有正常的事情,但也不运行 build.js。

How can I make npm run my build script?如何让 npm 运行我的构建脚本?

Edit: even simple bash commands don't seem to work, eg编辑:即使是简单的 bash 命令似乎也不起作用,例如

"scripts": {
    "build": "touch TESTFILE"
},

Doesn't make a file with that name.不制作具有该名称的文件。

Unfortunately npm build is already an internal command, as described in the docs :不幸的是npm build已经是一个内部命令,如文档中所述

This is the plumbing command called by npm link and npm install.这是由 npm link 和 npm install 调用的管道命令。 It should generally not be called directly.一般不应直接调用。

Because that command already exists, it always shadows over your "build": "node build.js" .因为该命令已经存在,所以它总是"build": "node build.js"在你的"build": "node build.js"

The fully-qualified way to run your own script is with run-script or its alias run :运行您自己的脚本的完全限定方式是使用run-script或其别名run

$ npm run build

npm start and others are the short-hand way, but is only an option when an existing npm command doesn't shadow it, like npm build does. npm start和其他是速记方式,但只有在现有 npm 命令不隐藏它时才可以选择,就像npm build那样。


For posterity (as others have mentioned) npm build is used by npm to build native C/C++ Node addons using node-gyp .对于后代(正如其他人所提到的), npm build使用 npm build 来使用node-gyp构建本机 C/C++ Node 插件。

The script named as "build" in package.json is not special in any way. package.json名为“build”的脚本在任何方面都没有什么特别之处。 The only way to get it to run is to call:让它运行的唯一方法是调用:

npm run-script build

There are some names which are called automatically by npm , but "build" is not one of them.有一些名称由 npm 自动调用,但“build”不是其中之一。 The full list is:完整列表是:

  • prepublish , publish , postpublish prepublishpublishpublish postpublish
  • preinstall , install , postinstall preinstallinstallpostinstall
  • preuninstall , uninstall , postuninstall uninstall preuninstalluninstalluninstall postuninstall
  • preversion , version , postversion preversion version , version , 后postversion
  • pretest , test , posttest pretest , test , posttest
  • prestop , stop , poststop prestopstoppoststop
  • prestart , start , poststart prestartstartpoststart
  • prerestart , restart , postrestart restart prerestartrestartpostrestart
  • preCUSTOM and postCUSTOM for custom script names. preCUSTOMpostCUSTOM用于自定义脚本名称。

好的,要自己运行构建,请使用:

npm run-script build

I had a problem with npm run build not printing anything.我遇到了npm run build不打印任何内容的问题。 ended up using npm run build --verbose to get the output I needed.最终使用npm run build --verbose来获得我需要的输出。

Npm build expects Npm 构建期望

A folder containing a package.json file in its root在其根目录中包含 package.json 文件的文件夹

Try using npm scripts in your package.json, like the classic npm start尝试在 package.json 中使用npm 脚本,就像经典的 npm start

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

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