代码之家  ›  专栏  ›  技术社区  ›  Chadd Yasin Özcan

Docker映像中的Bitbucket管道缺少NPM模块

  •  5
  • Chadd Yasin Özcan  · 技术社区  · 6 年前

    问题

    我的 Dockerfile bitbucket-pipelines.yml ?为什么bitbucket管道环境中缺少模块?

    错误

    当我尝试 npm run build 我的Vue2项目带有使用Bitbucket管道的webpack,我得到了有关缺少模块的错误。

    来自日志

    npm run build
    > people-is@1.0.0 build /opt/atlassian/pipelines/agent/build
    > node build/build.js
    module.js:549
        throw err;
        ^
    Error: Cannot find module 'cli-spinners'
    

    文件

    以下是配置文件。

    Dockerfile文件 - 构建cportwine/people is

    FROM node:8.10.0
    
    RUN npm install
    RUN npm install -g firebase-tools
    
    CMD [ "npm", "run", "build" ]
    

    bitbucket管道。yml公司

    image:
      name: cportwine/people-is
    pipelines:
      default:
        - step:
            script:
              - npm run build
    

    包裹json

    {
      "name": "people-is",
      "version": "1.0.0",
      "description": "A Vue.js project",
      "author": "cportwine",
      "private": true,
      "scripts": {
        "dev": "node build/dev-server.js",
        "start": "node build/dev-server.js",
        "build": "node build/build.js",
        "deploy": "firebase deploy --token $FIREBASE_TOKEN"
      },
      "dependencies": {
        "rxjs": "^5.5.8",
        "uuid": "^3.2.1",
        "vue": "^2.5.16",
        "vue-json-excel": "^0.1.9",
        "vue-router": "^2.8.1",
        "vue-rx": "^5.0.0",
        "vuefire": "^1.4.5",
        "vuetify": "^0.15.2"
      },
      "devDependencies": {
        "autoprefixer": "^7.2.6",
        "babel-core": "^6.22.1",
        "babel-loader": "^7.1.4",
        "babel-plugin-transform-runtime": "^6.22.0",
        "babel-preset-env": "^1.6.1",
        "babel-preset-stage-2": "^6.22.0",
        "babel-register": "^6.22.0",
        "chalk": "^2.3.2",
        "connect-history-api-fallback": "^1.5.0",
        "copy-webpack-plugin": "^4.5.1",
        "css-loader": "^0.28.11",
        "cssnano": "^3.10.0",
        "eslint": "^4.19.1",
        "eslint-config-standard": "^11.0.0",
        "eslint-friendly-formatter": "^3.0.0",
        "eslint-loader": "^1.9.0",
        "eslint-plugin-html": "^4.0.2",
        "eslint-plugin-promise": "^3.7.0",
        "eslint-plugin-standard": "^3.0.1",
        "eventsource-polyfill": "^0.9.6",
        "express": "^4.16.3",
        "extract-text-webpack-plugin": "^2.0.0",
        "file-loader": "^0.11.1",
        "firebase": "^4.12.0",
        "firebase-tools": "^3.17.7",
        "friendly-errors-webpack-plugin": "^1.1.3",
        "html-webpack-plugin": "^2.28.0",
        "http-proxy-middleware": "^0.17.3",
        "opn": "^5.3.0",
        "optimize-css-assets-webpack-plugin": "^2.0.0",
        "ora": "^1.4.0",
        "rimraf": "^2.6.0",
        "semver": "^5.5.0",
        "shelljs": "^0.7.6",
        "url-loader": "^0.5.8",
        "vue-loader": "^13.7.1",
        "vue-style-loader": "^3.1.2",
        "vue-template-compiler": "^2.5.16",
        "vuex": "^2.5.0",
        "webpack": "^2.6.1",
        "webpack-bundle-analyzer": "^2.11.1",
        "webpack-dev-middleware": "^1.12.2",
        "webpack-hot-middleware": "^2.21.2",
        "webpack-merge": "^4.1.2"
      },
      "engines": {
        "node": ">=8.10.0",
        "npm": ">= 5.6.0"
      },
      "browserslist": [
        "> 1%",
        "last 2 versions",
        "not ie <= 8"
      ],
      "main": "index.js",
      "repository": {
        "type": "git",
        "url": "git+https://chaddportwine@bitbucket.org/jahnelgroup/people-is.git"
      },
      "keywords": [],
      "license": "ISC",
      "homepage": "https://bitbucket.org/jahnelgroup/people-is#readme"
    }
    

    我所看到的

    当我 ls 这个 node_modules 文件夹中,它们不匹配。bitbucket管道中缺少模块。

    本地文件夹

    people-is/node_modules

    ...
    chalk
    char-spinner
    chardet
    check-types
    chokidar
    chownr
    cipher-base
    circular-json
    cjson
    clap
    class-utils
    clean-css
    cli-boxes
    cli-cursor
    cli-spinners
    cli-table
    cli-table2
    cli-width
    cliui
    ...
    

    bitbucket文件夹

    /opt/atlassian/pipelines/agent/build/node_modules

    哇,模块丢失了!

    ...
    chalk
    cli-cursor
    co
    ...
    

    我所尝试的

    我向 bitbucket管道。yml公司 npm install 在我建造之前。

    bitbucket管道。yml公司

    image:
      name: cportwine/people-is
    pipelines:
      default:
        - step:
            script:
              - npm install
              - npm run build
    

    这将添加一些附加模块(如 cli-spinners 从错误)到 /opt/atlassian/pipelines/agent/build/node\u模块

    bitbucket文件夹

    /opt/atlassian/pipelines/agent/build/node\u模块

    ...
    chalk
    char-spinner
    chardet
    check-types
    chokidar
    chownr
    cipher-base
    circular-json
    cjson
    clap
    class-utils
    clean-css
    cli-boxes
    cli-cursor
    cli-spinners
    cli-table
    cli-table2
    cli-width
    cliui
    clone
    clone-response
    co
    ...
    

    但是,由于缺少不同的模块,build命令仍然失败。

    错误

    > people-is@1.0.0 build /opt/atlassian/pipelines/agent/build
    > node build/build.js
    module.js:549
        throw err;
        ^
    Error: Cannot find module './_safeGet'
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Chadd Yasin Özcan    6 年前

    解决方案

    我现在可以创建应用程序了,但我不知道为什么!

    1-简化Dockerfile

    我删除了所有npm命令。也许 npm install 命令是多余的?使用Docker图像来 预安装 npm包。

    2-安装前卸下Node\u模块

    使用 bitbucket-pipelines.yml ,删除 node_modules 文件夹,然后执行 npm install -g npm npm安装 npm install -g firebase-tools

    文件更改

    bitbucket管道。yml公司 (添加的行)

    image:
      name: cportwine/people-is
    pipelines:
      default:
        - step:
            script:
              - rm -r node_modules              <---- remove
              - npm install -g npm              <---- install
              - npm install                     <---- install
              - npm install -g firebase-tools   <---- install
              - npm run build
    

    Dockerfile文件 (线路已删除)

    FROM node:8.10.0
    
                                                <---- remove
    
    CMD [ "npm", "run", "build" ]
    

    答复

    我不知道为什么要搬家 npm安装 塞进 bitbucket.pipelines.yml 解决了我在构建项目时遇到的问题。我认为Docker可以让我定义我的环境,例如安装node/npm和firebase的版本。管道将“运行”这一点。

    如果有人能解释我遗漏了什么,我会接受这个答案。

        2
  •  1
  •   Chadd Yasin Özcan    6 年前

    答复

    我收到 support 来自Atlassian团队

    1. 离开 npm install -g firebase 在docker图像中。
    2. 移动 npm install 从docker图像到 bitbucket管道。yml文件。

    原因

    这个 node_modules 文件夹列在中 .gitignore

    tl;博士

    我的错误-我忘了 。gitignore 以及这如何影响 node\u模块 源代码管理中的文件夹,例如Bitbucket管道。

    我在看我的 地方的 node\u模块 本地工作的文件夹和建筑。

    然而

    这个 node\u模块 在源代码管理中,根据设计,它与我的本地文件夹不同步,因为它包含在 。gitignore 文件

    所以

    我有必要 rm node_modules npm安装 使用bitbucket管道。yml。现在,BitPipes可以找到我在本地安装的模块。

    这是维护 package.json ,但我感到困惑。