如何解决使用 Docker 构建我的 Vue.js 应用程序时,npm install 失败
Dockerfile
FROM node:latest as builder
workdir /app
# copy and install node modules
copY package*.json ./
RUN npm install
# copy and build for production
copY . /app/
RUN npm run build --prod
# Configure Nginx
FROM Nginx:1.17.3-alpine
copY ./docker/Nginx.conf /etc/Nginx/Nginx.conf
workdir /usr/share/Nginx/html
copY --from=builder /app/dist/ .
# copy entrypoint script as /entrypoint.sh
copY ./docker/entrypoint.sh /entrypoint.sh
EXPOSE 80
# Grant Linux permissions and run entrypoint script
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Start Nginx
CMD ["Nginx","-g","daemon off;"]
这是到达 Dockerfile 中的 npm install 行后的输出。
npm ERR! ../src/libsass/src/cencode.c: In function 'base64_encode_block':
npm ERR! ../src/libsass/src/cencode.c:48:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
npm ERR! result = (fragment & 0x003) << 4;
npm ERR! ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! ../src/libsass/src/cencode.c:52:2: note: here
npm ERR! case step_B:
npm ERR! ^~~~
npm ERR! ../src/libsass/src/cencode.c:62:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
npm ERR! result = (fragment & 0x00f) << 2;
npm ERR! ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! ../src/libsass/src/cencode.c:66:2: note: here
npm ERR! case step_C:
npm ERR! ^~~~
npm ERR! ../src/libsass/src/functions.cpp: In function 'void Sass::Functions::handle_utf8_error(const Sass::ParserState&,Sass::Backtraces)':
npm ERR! ../src/libsass/src/functions.cpp:110:20: warning: catching polymorphic type 'class utf8::invalid_code_point' by value [-Wcatch-value=]
npm ERR! catch (utf8::invalid_code_point) {
npm ERR! ^~~~~~~~~~~~~~~~~~
npm ERR! ../src/libsass/src/functions.cpp:114:20: warning: catching polymorphic type 'class utf8::not_enough_room' by value [-Wcatch-value=]
npm ERR! catch (utf8::not_enough_room) {
npm ERR! ^~~~~~~~~~~~~~~
npm ERR! ../src/libsass/src/functions.cpp:118:20: warning: catching polymorphic type 'class utf8::invalid_utf8' by value [-Wcatch-value=]
npm ERR! catch (utf8::invalid_utf8) {
npm ERR! ^~~~~~~~~~~~
npm ERR! ../src/libsass/src/json.cpp: In function 'char* json_encode_string(const char*)':
npm ERR! ../src/libsass/src/json.cpp:405:15: warning: catching polymorphic type 'class std::exception' by value [-Wcatch-value=]
npm ERR! catch (std::exception) {
npm ERR! ^~~~~~~~~
npm ERR! ../src/libsass/src/json.cpp: In function 'char* json_stringify(const JsonNode*,const char*)':
npm ERR! ../src/libsass/src/json.cpp:424:15: warning: catching polymorphic type 'class std::exception' by value [-Wcatch-value=]
npm ERR! catch (std::exception) {
npm ERR! ^~~~~~~~~
npm ERR! In file included from /root/.node-gyp/16.1.0/include/node/v8.h:30,npm ERR! from /root/.node-gyp/16.1.0/include/node/node.h:63,npm ERR! from ../../nan/nan.h:56,npm ERR! from ../src/binding.cpp:1:
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h: In function 'void v8::internal::PerformCastCheck(T*)':
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:38: error: 'remove_cv_t' is not a member of 'std'
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^~~~~~~~~~~
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:38: note: suggested alternative: 'remove_cv'
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^~~~~~~~~~~
npm ERR! remove_cv
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:38: error: 'remove_cv_t' is not a member of 'std'
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:38: note: suggested alternative: 'remove_cv'
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^~~~~~~~~~~
npm ERR! remove_cv
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:50: error: template argument 2 is invalid
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:63: error: '::Perform' has not been declared
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^~~~~~~
npm ERR! /root/.node-gyp/16.1.0/include/node/v8-internal.h:452:63: note: suggested alternative: 'herror'
npm ERR! !std::is_same<Data,std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! ^~~~~~~
npm ERR! herror
npm ERR! ../src/binding.cpp: In function 'Nan::NAN_METHOD_RETURN_TYPE render(Nan::NAN_METHOD_ARGS_TYPE)':
npm ERR! ../src/binding.cpp:284:98: warning: cast between incompatible function types from 'void (*)(uv_work_t*)' {aka 'void (*)(uv_work_s*)'} to 'uv_after_work_cb' {aka 'void (*)(uv_work_s*,int)'} [
nction-type]
npm ERR! int status = uv_queue_work(uv_default_loop(),&ctx_w->request,compile_it,(uv_after_work_cb)MakeCallback);
npm ERR! ^~~~~~~~~~~~
npm ERR! ../src/binding.cpp: In function 'Nan::NAN_METHOD_RETURN_TYPE render_file(Nan::NAN_METHOD_ARGS_TYPE)':
npm ERR! ../src/binding.cpp:320:98: warning: cast between incompatible function types from 'void (*)(uv_work_t*)' {aka 'void (*)(uv_work_s*)'} to 'uv_after_work_cb' {aka 'void (*)(uv_work_s*,(uv_after_work_cb)MakeCallback);
npm ERR! ^~~~~~~~~~~~
npm ERR! In file included from ../../nan/nan.h:56,npm ERR! from ../src/binding.cpp:1:
npm ERR! ../src/binding.cpp: At global scope:
npm ERR! /root/.node-gyp/16.1.0/include/node/node.h:806:43: warning: cast between incompatible function types from 'void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)' {aka 'void (*)(v8::Local<v8::Objec
'node::addon_register_func' {aka 'void (*)(v8::Local<v8::Object>,v8::Local<v8::Value>,void*)'} [-Wcast-function-type]
npm ERR! (node::addon_register_func) (regfunc),\
npm ERR! ^
npm ERR! /root/.node-gyp/16.1.0/include/node/node.h:840:3: note: in expansion of macro 'NODE_MODULE_X'
npm ERR! NODE_MODULE_X(modname,regfunc,NULL,0) // NOLINT (readability/null_usage)
npm ERR! ^~~~~~~~~~~~~
npm ERR! ../src/binding.cpp:358:1: note: in expansion of macro 'NODE_MODULE'
npm ERR! NODE_MODULE(binding,RegisterModule);
npm ERR! ^~~~~~~~~~~
npm ERR! make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` Failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/app/node_modules/node-gyp/lib/build.js:262:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:365:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Linux 5.10.25-linuxkit
npm ERR! gyp ERR! command "/usr/local/bin/node" "/app/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /app/node_modules/node-sass
npm ERR! gyp ERR! node -v v16.1.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build Failed with error code: 1
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-05-12T18_13_32_395Z-debug.log
Package.json
{
"name": "titan","version": "1.0.0","private": true,"scripts": {
"serve": "vue-cli-service serve --port 8080","dev": "npm run serve --no-progress","build": "vue-cli-service build","lint": "vue-cli-service lint","test:unit": "vue-cli-service test:unit"
},"dependencies": {
"@azure/msal-browser": "^2.5.1","azure-maps-control": "^2.0.23","chart.js": "^2.9.3","chartist": "0.11.0","eslint-plugin-promise": "^4.2.1","eslint-plugin-standard": "^4.0.1","i18n": "^0.8.5","jspdf": "^1.5.3","moment": "^2.26.0","moment-timezone": "^0.5.32","msal": "^1.3.3","node-sass": "^4.14.1","npm": "^7.12.1","papaparse": "^5.2.0","pdfmake": "^0.1.65","sass-loader": "^7.3.1","usps-webtools": "^1.0.3","v-money": "^0.8.1","vue": "^2.6.11","vue-chartist": "^2.1.2","vue-chartjs": "^3.5.0","vue-Meta": "^1.5.2","vue-the-mask": "^0.11.1","vuetify": "^2.3.1"
},"devDependencies": {
"@mdi/font": "4.5.95","@vue/cli-plugin-babel": "^3.12.1","@vue/cli-plugin-eslint": "^3.12.1","@vue/cli-plugin-unit-jest": "^4.2.3","@vue/cli-service": "^4.2.3","@vue/eslint-config-standard": "^3.0.1","@vue/test-utils": "1.0.0-beta.29","axios": "^0.19.2","eslint": "^5.16.0","eslint-config-vuetify": "^0.5.0","eslint-plugin-node": "^11.0.0","jest-junit": "^10.0.0","material-design-icons-iconfont": "^3.0.3","stylus": "^0.54.7","stylus-loader": "^3.0.1","vue-analytics": "^5.22.1","vue-i18n": "^7.4.0","vue-router": "^3.1.6","vue-template-compiler": "^2.6.11","vuex": "^3.1.2","vuex-router-sync": "^5.0.0"
},"jest": {
"preset": "@vue/cli-plugin-unit-jest","collectCoverage": true,"reporters": [
"default","jest-junit"
],"coverageReporters": [
"cobertura","html"
]
},"jest-junit": {
"suiteName": "jest tests","output": "test/junit.xml","classNameTemplate": "{classname} - {title}","titleTemplate": "{classname} - {title}","ancestorSeparator": " > ","usePathForSuiteName": "true"
}
}
我已经尝试过的事情:
老实说,我什至不知道错误意味着什么,而且我不知道从哪里开始。最奇怪的是,这只发生在我工作的电脑上。我的家用 PC 具有相同的项目,可以很好地构建映像,没有错误。任何人都对如何解决这个问题有任何想法?谢谢。
更新:
更改 Dockerfile 中的第一行以使用来自节点的 14.10.0 版本修复了该问题:
FROM node:14.10.0 as builder
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。