简体   繁体   中英

Drone CI can't find Node module that's 100% definitely there

My project is a pretty simple website compiled with gulp.

Gulp does:

  • PostCSS -> CSS; and
  • Pug -> HTML; and
  • Some image resizing

Nothing too shocking. It runs on my machine. It runs on my other machine. No sweat. All good.

It used to run on Travis CI (before I ran out of credits:( ). So I installed Drone CI. Everything's working fine, it's doing what it's meant to, all except for actually building my project.

npm i runs fine. I see node_modules in a ls executed immediately after. But when I then run npm run build (itself just gulp build - gulp is included in package.json 's dependencies field), Drone outputs this error:

+ 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

Here's my.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: {}

and my package.json (name, author and repo removed):

{
  "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"
  ]
}

I don't get it. Search engines aren't much help, they all mention Dockerfile-specific things, and, as I'm not dealing with a Dockerfile here, it's not much use.

Any ideas?

Epic!

It turns out setting NODE_ENV=production makes npm ignore devDependencies. Removing that from.drone.yml to get a step like this:

 - name: cry                                                                                                                                    
   privileged: true                                                                                                                             
   image: node:14                                                                                                                               
   volumes:                                                                                                                                     
     - name: nodemod                                                                                                                            
       path: /node_modules                                                                                                                      
   commands:                                                                                                                                    
     - echo "You heard me. Start sobbing."                                                                                                      
     - npm run build      

This makes sense now. Thank you @David784!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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