Error Package exports forapp node_modules koa do not define a valid . target

用dockerfile构建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. (/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  | }

解决方法:

KOA版本问题,修改package.json中的KOA版本,看哪个版本可以。

dockerfile如下

FROM keymetrics/pm2:latest-alpine

ADD . /app/

WORKDIR /app

#RUN npm install -g cnpm –registry=https://registry.npm.taobao.org

COPY repositories /etc/apk/repositories

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 [email protected]
卸载原有的KOA,加载之前测试确定好的KOA,即可正常访问。

你可能感兴趣的:(docker,node,npm,docker,koa)