我的项目是一个用gulp编译的非常简单的网站。
杯:
- PostCSS→CSS;和
- 哈巴狗→HTML;和
- 调整图片大小
没什么太令人震惊的。它在我的机器上运行。它在我的另一台机器上运行。没有汗水。所有好。
它曾经在Travis CI上运行(在我用完学分之前)。所以我安装了Drone CI。一切都很好,它在做它应该做的,除了实际构建我的项目。
npm i
运行良好。我看到node_modules
在紧接着执行的ls
中。当我然后运行npm run build
(本身只是gulp build
- gulp包含在package.json
的依赖项字段),无人机输出此错误:
+ npm run build
> tribute-page@0.0.0 build /drone/src
> gulp build
Error: Cannot find module 'gulp-postcss'
Require stack:
- /drone/src/gulpfile.js
- /drone/src/node_modules/gulp/node_modules/gulp-cli/lib/shared/require-or-import.js
- /drone/src/node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js
- /drone/src/node_modules/gulp/node_modules/gulp-cli/index.js
- /drone/src/node_modules/gulp/bin/gulp.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/drone/src/gulpfile.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/drone/src/gulpfile.js',
'/drone/src/node_modules/gulp/node_modules/gulp-cli/lib/shared/require-or-import.js',
'/drone/src/node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js',
'/drone/src/node_modules/gulp/node_modules/gulp-cli/index.js',
'/drone/src/node_modules/gulp/bin/gulp.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tribute-page@0.0.0 build: `gulp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tribute-page@0.0.0 build 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! /root/.npm/_logs/2021-01-17T14_14_03_103Z-debug.log
我的。drone.yml:
---
kind: pipeline
type: docker
name: default
clone:
depth: 2
steps:
- name: install
image: node:14
volumes:
- name: nodemod
path: /node_modules
pull: if-not-exists
commands:
- npm i
- ls
environment:
NODE_ENV: production
- name: cry
privileged: true
image: node:14
volumes:
- name: nodemod
path: /node_modules
commands:
- echo "You heard me. Start sobbing."
- npm run build
environment:
NODE_ENV: production
volumes:
- name: nodemod
temp: {}
和我的包。Json(删除名称、作者和repo):
{
"version": "0.0.0",
"description": "a tribute to... some guy",
"main": "main.js",
"license": "MIT",
"private": true,
"type": "commonjs",
"devDependencies": {
"@types/gulp": "4.0.8",
"@types/node": "14.14.20",
"@typescript-eslint/eslint-plugin": "4.12.0",
"@typescript-eslint/parser": "4.12.0",
"cssnano-preset-advanced": "4.0.7",
"eslint": "7.17.0",
"eslint-config-prettier": "7.1.0",
"eslint-config-standard-with-typescript": "19.0.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.1.0",
"gh-pages": "^3.1.0",
"gulp-minify": "3.1.0",
"gulp-postcss": "9.0.0",
"gulp-responsive": "3.0.1",
"husky": "4.3.7",
"lint-staged": "10.5.3",
"postcss": "8.2.4",
"postcss-uncss": "0.17.0",
"prettier": "2.2.1",
"ts-node": "9.1.1",
"typescript": "4.1.3",
"uncss": "0.17.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
},
"scripts": {
"test": "tsc && yarn eslint src/**/* --ext .js,.jsx,.ts,.tsx",
"build": "gulp build"
},
"dependencies": {
"autoprefixer": "10.2.1",
"cssnano": "4.1.10",
"gulp": "^4.0.2",
"gulp-pug": "4.0.1",
"gulp-typescript": "6.0.0-alpha.1",
"postcss-partial-import": "4.1.0",
"pug": "2.0.4"
},
"browserslist": [
"defaults",
"not IE 11",
"maintained node versions"
]
}
我不明白。搜索引擎没有多大帮助,它们都提到了Dockerfile特定的东西,而且,因为我这里没有处理Dockerfile,所以它没有多大用处。
任何想法?
史诗!
原来设置NODE_ENV=production
会让npm忽略devDependencies。从。drone中移除。得到这样的步骤:
- name: cry
privileged: true
image: node:14
volumes:
- name: nodemod
path: /node_modules
commands:
- echo "You heard me. Start sobbing."
- npm run build
现在说得通了。谢谢你@David784!