我正在尝试为我的项目测试 npm 包,这样每次我尝试安装模块时,即运行npm install <module> 脚本时,必须在安装该模块之前运行。预安装脚本仅适用于npm install而不适用于npm install <module>.
例如:- 如果运行npm install request。它应该运行一个脚本,在安装模块之前向我显示请求模块的所有依赖项。提前致谢。
我有一个 bash 脚本,可以启动服务器,然后运行一些功能测试。它必须在一个脚本中发生,所以我在后台运行服务器。这一切都通过 2 个 npm 命令发生:start:nolog和test:functional.
都好。但是输出中有很多我不关心的问题:
? ./functional-tests/runInPipeline.sh
(... "good" output here)
> @co/foo@2.2.10 pretest:functional /Users/jcol53/Documents/work/foo
> curl 'http://localhost:3000/foo' -s -f -o /dev/null || (echo 'Website must be running locally for functional tests.' && exit 1)
> @co/foo@2.2.10 test:functional /Users/jcol53/Documents/work/foo
> npm run --prefix functional-tests test:dev:chromeff
> @co/foo-functional-tests@1.0.0 test:dev:chromeff /Users/jcol53/Documents/work/foo/functional-tests
> testcafe chrome:headless,firefox:headless ./tests/**.test.js -r junit:reports/functional-test.junit.xml -r html:reports/functional-test.html --skip-js-errors
Run Code Online (Sandbox Code Playgroud)
那里有很多我不需要的行。我可以抑制@co/foo-functional-tests等行吗?他们没有告诉我任何值得...
npm run -s 杀死命令的所有输出,这不是我要找的。
这可能是不可能的,但这没关系,我很好奇,也许我错过了什么......
假设我的 package.json 中有以下脚本
{
"scripts": {
"release:public": "....",
"release:beta": "...."
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我想添加一个prerelease对于 和 都相同的release:public脚本release:beta。在这两个脚本之前是否可以有一种prerelease:*或另一种方式运行?
我的项目中需要一个模块来下载私有的npm软件包。为此,我正在使用一个.npmrc文件来提供下载软件包所需的只读令牌。为了将npm提供的令牌保留在文件之外,我希望将其添加为环境变量,并使其在文件中扩展。例如:
# .npmrc
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Run Code Online (Sandbox Code Playgroud)
NPM_TOKEN在安装引用之前,我不知道如何将其添加到环境中。我尝试使用npm预安装脚本:
"preinstall": "NPM_READ_ONLY_TOKEN=my_token_goes_here_foo_bar"**
但是我仍然遇到同样的错误:
Error: Failed to replace env in config: ${NPM_READ_ONLY_TOKEN}
Run Code Online (Sandbox Code Playgroud)
我尝试使用echo命令进行测试,以查看是否preinstall在.npmrc变量扩展之前运行,但显然没有。我会收到错误,但看不到我的回声日志。我似乎在这里错过了一些东西。
我知道将令牌放入package.json会破坏将令牌从.npmrc文件中拉出的目的。我实际上正在使用提供环境配置服务的服务,该服务将用于运行命令并获取所需的令牌。例如TOKEN=config_service_value。
我刚刚使用 Node.js 初始化了一个新项目,并尝试使 package.json 文件中的脚本正常工作。
例如我有下一个 package.json 文件:
{
"name": "my-app-name",
"version": "1.0.0",
"description": "Description server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Something LTD",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cron": "^1.3.0",
"crypto": "^1.0.1",
"docusaurus-init": "^1.0.2",
"exceljs": "^1.5.0",
"express": "^4.16.3",
"express-limiter": "^1.6.1",
"jsonwebtoken": "^8.3.0",
"mongojs": "^2.6.0",
"npm": "^6.1.0",
"point-in-polygon": "^1.0.1",
"request": "^2.87.0",
"socket.io": "^2.1.1",
"socket.io-redis": "^5.2.0",
"xmldom": "^0.1.27"
},
"devDependencies": {
"t4u": "^1.0.0"
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我要么试图运行npm test …
我正在尝试运行一个反应项目。在我运行命令后: npm start ,它给了我一个错误:
sh: SET: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! materials-trace@0.1.0 start: `SET PORT=3100 && node scripts/start.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the materials-trace@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jzhu321/.npm/_logs/2019-04-22T09_29_51_770Z-debug.log …Run Code Online (Sandbox Code Playgroud) 运行 Windows 10(内部版本 18362),使用 Node.js v10.16.0、npm v6.9.0 和 .Net Core v2.2.300。我通过 File->New Project 在 Visual Studio 2017 中创建了一个示例 React/Redux 应用程序,选择 ASP.NET Core Web 应用程序,然后选择 React.js 和 Redux。但是,当通过 Visual Studio 启动应用程序时,浏览器遇到 500 错误并说:
An unhandled exception occurred while processing the request.
AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was: 'rimraf' is not recognized as an internal or external command, …Run Code Online (Sandbox Code Playgroud) 我已经使用 Vue.js 和 express.js 构建了一个应用程序。目前我必须打开两个终端窗口并npm run serve在一个和npm start另一个中运行。我想让服务器在 Vue.js 应用程序在同一终端中构建后运行。我在这篇文章中读到,我可以通过将两个package.json脚本链接在一起来运行这两个脚本,但我一生都无法弄清楚如何运行。我的项目结构如下:
??? project
??? _frontend
| ??? package.json
??? backend
| ??? package.json
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
1st try - "serve": "vue-cli-service serve && (cd ../server && npm start)"
2nd try - "serve": "vue-cli-service serve && (cd ../server && npm run start)"
3rd try - "serve": "vue-cli-service serve && (cd ../server) && npm start"
Run Code Online (Sandbox Code Playgroud)
Vue.js 应用程序构建并运行得很好,但服务器没有启动。我也尝试在服务器上进行相反的操作,package.json服务器启动但应用程序未构建。这是由于文件夹设置而我无法完成的事情还是我做错了什么?
我正在尝试在codesandbox 中运行json-servernpm。我创建了一个普通项目并添加了对package.json. 我必须运行一个脚本json-server --watch db.json。
Codesandbox 有没有办法运行脚本?
npm-scripts ×10
npm ×9
node.js ×8
javascript ×2
reactjs ×2
codesandbox ×1
express ×1
npm-install ×1
npm-run ×1
nvm ×1
package.json ×1
vue.js ×1
windows-10 ×1