用dockerfile構建node後端鏡像,出現以下問題。node
Error: Package exports for '/app/node_modules/koa' do not define a valid '.' target
11:38:03 0|gov-test | at resolveExportsTarget (internal/modules/cjs/loader.js:460:13)
11:38:03 0|gov-test | at resolveExports (internal/modules/cjs/loader.js:393:16)
11:38:03 0|gov-test | at Function.Module._findPath (internal/modules/cjs/loader.js:492:20)
11:38:03 0|gov-test | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:787:27)
11:38:03 0|gov-test | at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.j
11:38:03 0|gov-test | at require (internal/modules/cjs/helpers.js:74:18)
11:38:03 0|gov-test | at Object.<anonymous> (/app/server.js:39:13)
11:38:03 0|gov-test | at Module._compile (internal/modules/cjs/loader.js:971:30)
11:38:03 0|gov-test | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
11:38:03 0|gov-test | at Module.load (internal/modules/cjs/loader.js:822:32) {
11:38:03 0|gov-test | code: 'MODULE_NOT_FOUND'
11:38:03 0|gov-test | }
docker
解決方法:npm
KOA版本問題,修改package.json中的KOA版本,看哪一個版本能夠。json
dockerfile以下後端
FROM keymetrics/pm2:latest-alpinebabel
ADD . /app/app
WORKDIR /appkoa
#RUN npm install -g cnpm –registry=https://registry.npm.taobao.org測試
COPY repositories /etc/apk/repositoriesui
RUN npm config set registry https://registry.npm.taobao.org RUN npm install #RUN npm install @babel/plugin-transform-modules-commonjs RUN npm uninstall koa RUN npm install koa@2.12.1 卸載原有的KOA,加載以前測試肯定好的KOA,便可正常訪問。