node.js – 在docker容器中安装npm时损坏的依赖项

我正在构建并运行以下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安装其文件已损坏的特定模块,那么它们将得到修复并且gulp成功.
如果我在主机上运行npm install和gulp,一切正常.
我究竟做错了什么?

最佳答案 您需要设置正确的区域设置.大多数泊坞窗图像不指定区域设置.

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

点赞