错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:在 /app/node_modules/@babel/helper-compilation-targets/package.json 中没有解决“导出”主要问题

Sim*_*mon 26 node.js travis-ci docker nuxt.js

我在 travis CI 管道中构建我的 nuxt 图像时遇到问题。我的本地环境是 ubuntu 18.04 - docker version 19.03.11 docker-compose version 1.24.1 我能够在本地构建和运行我的图像,但是在 travis CI 上我收到以下错误

Step 5/7 : RUN npm run build
 ---> Running in d3e9433b79f0
> nuxt_app@1.0.0 build /app
> nuxt build
? Production build
? Builder initialized
? Nuxt files generated
? Compiling Client
? Starting type checking service...
? Using 1 worker with 2048MB memory limit
? Client: Compiled with some errors in 1.62s
Hash: 1b9cf81215d31b9f0ed3
Version: webpack 4.43.0
Time: 1624ms
Built at: 06/07/2020 2:20:27 PM
                  Asset      Size  Chunks               Chunk Names
4bff68cc9fb4c003b7f2.js  1.49 KiB       1  [immutable]  runtime
b4f22db01be076446c20.js   1.4 KiB       0  [immutable]  app
Entrypoint app = 4bff68cc9fb4c003b7f2.js b4f22db01be076446c20.js
ERROR in ./.nuxt/client.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /app/node_modules/@babel/helper-compilation-targets/package.json
    at applyExports (internal/modules/cjs/loader.js:491:9)
    at resolveExports (internal/modules/cjs/loader.js:507:23)
    at Function.Module._findPath (internal/modules/cjs/loader.js:635:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:953:27)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/app/node_modules/@babel/preset-env/lib/debug.js:8:33)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/app/node_modules/@babel/preset-env/lib/index.js:11:14)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
 @ multi ./.nuxt/client.js app[0]
 FATAL  Nuxt build error
  at WebpackBundler.webpackCompile (node_modules/@nuxt/webpack/dist/webpack.js:5326:21)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)
  at async WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5275:5)
  at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:5598:5)
  at async Object.run (node_modules/@nuxt/cli/dist/cli-build.js:100:7)
  at async NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-command.js:2575:7)
Run Code Online (Sandbox Code Playgroud)

我的特拉维斯 CI

sudo: required

dist: trusty

services:
    - docker

# language: node_js
# node_js: 12

before_install:
    - sudo rm /usr/local/bin/docker-compose
    - sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    - sudo chmod +x /usr/local/bin/docker-compose
    - sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
    - sudo chmod 400 -R .ops/ssh/*

# before_script:
#     - my_script

script:
    - .ops/build.sh
    - .ops/push.sh
Run Code Online (Sandbox Code Playgroud)

我的 docker-compose 文件

    web:
        build:
            context: ${GITROOT:-.}
            dockerfile: Dockerfile.web
        image: moovinit_web
        container_name: moovinit_web
        command: npm start
        environment:
            WEB_PORT: ${WEB_PORT:-3200}
            API_URL: ${API_URL:-http://api:3201}
            <<: *node-common
Run Code Online (Sandbox Code Playgroud)

为什么它建立在我的笔记本电脑上而不是建立在 travis 上?

Arn*_*man 45

我有类似的问题。npm install @babel/helper-compilation-targets --save-dev 解决了这个情况


小智 35

使用npm update为我修复了相同的错误。

  • 与本页上的大多数答案一样,这是一个 Voodoo 答案:没有解释为什么会抛出错误,假设的解决方案应该做什么(有任何副作用吗?)以及为什么应该修复它。因此,有时它解决了问题(但可能引入新问题),有时它失败(并且仍可能引入新问题)。 (6认同)

edi*_*999 15

对我有用的解决方案只是更新节点。

例如,使用节点 12.22.0 和 14.17.4 都可以。请注意,13.x 的节点版本根本无法工作。

我也遇到了这个问题,发现这个错误似乎是某些 Node js 版本特有的。

  • 节点 13.14.0、节点 12.18.4、12.19.0、12.19.1 显示错误:ERR_PACKAGE_PATH_NOT_EXPORTED
  • 对于节点 12.20.0、节点 14.17.4,不会抛出该错误。

问题是已经创建了一个新的导出系统,如下定义:

https://github.com/nodejs/modules/issues/535

此功能允许使用 glob 定义包中可能允许的要求,如下所示:

  "exports": {
    ".": {
      "import": "./dist/pako.esm.mjs",
      "require": "./index.js"
    },
    "./package.json": "./package.json",
    "./dist/*": "./dist/*",
    "./lib/*": "./lib/*",
    "./lib/zlib/*": "./lib/zlib/*",
    "./lib/utils/*": "./lib/utils/*"
  },
Run Code Online (Sandbox Code Playgroud)

此功能的拉取请求可以在这里找到: https: //github.com/nodejs/modules/issues/535

现在,如果您在导出文件中包含使用此新“glob”功能的包,那么如果您需要该特定文件,它可能会失败。


MH *_*har 11

我遇到了这个问题,我通过删除锁定文件然后重新安装所有内容来解决它。

这对每个人来说可能不是一个好的解决方案,但它对我有用。

这正是我所做的。

  1. 删除锁定文件。在这种情况下,我正在使用,yarn所以我需要删除该yarn.lock文件。如果您使用npm的锁定文件package-lock.json.
# for yarn user
rm yarn.lock

# for npm user
rm package-lock.json
Run Code Online (Sandbox Code Playgroud)
  1. 然后我重新安装所有依赖项。
# for yarn user
yarn install

# for npm user
npm install
Run Code Online (Sandbox Code Playgroud)

  • @SlavaFominII 是的,这就是为什么要加上免责声明“这可能不是每个人的好解决方案,但它对我有用。” (3认同)

Byu*_*usa 9

快速解决:

纱线用

yarn upgrade
Run Code Online (Sandbox Code Playgroud)

对于 npm

npm update
Run Code Online (Sandbox Code Playgroud)


Sim*_*mon 8

固定于npm update && npm audit fix --force