在docker容器中安装npm时损坏的依赖项

时间:2016-04-06 13:22:09

标签: node.js bash docker npm gulp

我正在构建并运行以下docker-compose文件

gulp:
  image: node:4.4
  volumes:
    - ./admin:/node
  working_dir: /node
  command: bash -c "npm install && npm install -g gulp-cli && gulp dev"

npm install命令正常,但gulp失败并出现以下错误:

admin-gulp_1 | npm info ok 
admin-gulp_1 | /node/node_modules/gulp-eslint/node_modules/eslint/lib/util/source-code.js:88
admin-gulp_1 | SourceCode.splitLines = function(text) {
admin-gulp_1 | ^
admin-gulp_1 | 
admin-gulp_1 | ReferenceError: SourceCode is not defined
admin-gulp_1 |     at Object.<anonymous> (/node/node_modules/gulp-eslint/node_modules/eslint/lib/util/source-code.js:88:1)
admin-gulp_1 |     at Module._compile (module.js:409:26)
admin-gulp_1 |     at Object.Module._extensions..js (module.js:416:10)
admin-gulp_1 |     at Module.load (module.js:343:32)
admin-gulp_1 |     at Function.Module._load (module.js:300:12)
admin-gulp_1 |     at Module.require (module.js:353:17)
admin-gulp_1 |     at require (internal/module.js:12:17)
admin-gulp_1 |     at Object.<anonymous> (/node/node_modules/gulp-eslint/node_modules/eslint/lib/eslint.js:21:18)
admin-gulp_1 |     at Module._compile (module.js:409:26)
admin-gulp_1 |     at Object.Module._extensions..js (module.js:416:10)
sf_admin-gulp_1 exited with code 1

当我cat /node/node_modules/gulp-eslint/node_modules/eslint/lib/util/source-code.js时,我看到一些奇怪的角色:

/**
 * Check to see if its a ES6 export declaration
 * @param {ASTNode} astNode - qa��  B0��    ���7�sa��   B0��    ���7�sa��   B0��    ���7�va��   B0��    ���7|a��    B0���L0��
���$1y���=�s0��1A�$1����=�s0��1A�$1����=�L0���,����=���=�s0��1A�$1!���= B0���޳�7�za��೙7�a��I\�î31A�$11A�$1�B�$1�B�$11s0��1A�$11A�$11s0��1A�$11A�$1!q0��1A�$1I���=p��g�)�node_modules/gulp-plumber/node_modules/gulp-util/node_modules/dateformat/node_modules/meow/node_modules/read-pkg-up/node_modules/read-pkg/node_modules/load-json-file/node_modules/graceful-fs$1��g�)�node_modules/gulp-plumber/node_modules/gulp-util/node_modules/dateformat/node_modules/meow/node_modules/read-pkg-up/node_modules/read-pkg/node_modules/load-json-filest:2iC0��@1A�$11s0��1A�$11A�$1!q0��1A�$1����=iC0���y%hc�3�@rU11]0��1A�$1Y�dZ4ٞ0��1A�$11A�$1�S��yA�$1���v<rCommentAfter = tokensAndCommentsStore.getTokenAfter;

    // don't allow modification of this object
    Object.freeze(this);
    Object.freeze(this.lines);
}

/**
 * Split the source code into multiple lines based on the line delimiters
 * @param {string} text Source code as a string
 * @returns {string[]} Array of source code lines
 * @public
 */
SourceCode.splitLines = function(text) {
    return text.split(/\r\n|\r|\n|\u2028|\u2029/g);
};

如果我重复此过程,则错误并不总是发生在同一个文件中,但始终是npm个安装的任何文件中的错误字符。 如果我然后在容器中运行bash并单独npm install其文件已损坏的特定模块,则它们将被修复并gulp成功。 如果我在主机中运行npm installgulp,一切正常。 我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要将区域设置设置为正确。大多数泊坞窗图像不指定区域设置。

FROM ubuntu:lastest

RUN locale-gen en_US.UTF-8  
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8

来源Docker and Locales