Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /app/node_modules/@babel/helper-compilation-targets/package.json
Asked Answered
P

12

88

I'm having trouble building my nuxt images in a travis CI pipeline. My local environment is ubuntu 18.04 - docker version 19.03.11 docker-compose version 1.24.1 I'm able to build and run my images locally but on the travis CI I get the following error

Step 5/7 : RUN npm run build
 ---> Running in d3e9433b79f0
> [email protected] 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)

My travis 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

my docker-compose file

    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

Why does it build on my laptop but not on travis?

Pernas answered 7/6, 2020 at 14:29 Comment(0)
P
103

Using npm update fixed the same error for me.

Polytonality answered 25/6, 2020 at 11:50 Comment(5)
An update of @babel/ modules is enough. Worked for me and for some open source too.Telega
This fixed the issue for me, and I had it with discord.js.Petrillo
Like most answers on this page, it's a Voodoo answer: no explanation why the error is thrown, what the supposed solution supposedly does (are there any side effects?) and why it is supposed to fix it. Consequently, sometimes it solves the problem (but may introduce new ones), and sometimes it fails (and may still introduce new ones).Puto
Any reason why it occurred? and how this command fix the issueSelfsacrifice
@Puto sometimes you have to embrace the Voodoo -- (also, worked for me)Vetter
W
59

I had the similar problem. npm install @babel/helper-compilation-targets --save-dev solved this situation

Whacky answered 13/6, 2020 at 3:57 Comment(2)
I encountered this issue while building my app in Heroku and this solves it for meAinslee
I've get error when uploaded netlify, bu run npm install @babel/helper-compilation-targets --save-dev and works .Gwen
V
27

I was experiencing this issue and I resolved it by removing the lock file and then reinstall everything again.

This is probably not a good solution for everyone but it works for me.

Here's exactly what I have done.

  1. Removing the lock file. In this case I'm using yarn so I need to delete the yarn.lock file. If you're using npm the lock file is package-lock.json.
# for yarn user
rm yarn.lock

# for npm user
rm package-lock.json
  1. And then I reinstall all the dependencies.
# for yarn user
yarn install

# for npm user
npm install
Vaticination answered 14/9, 2020 at 12:19 Comment(3)
You should never delete the lock file, it serves an important security-related purpose. The deep update command would be a much better choice.Cribwork
@SlavaFominII yeah, that's why put disclaimer This is probably not a good solution for everyone but it works for me.Vaticination
it worked for meNaval
A
15

The solution that worked for me was simply to update node.

For, example, using node 12.22.0 worked, as well as 14.17.4. Note that node version of 13.x will not work at all.

I was also having this issue and found out that this error seems to be specific to some node js versions.

  • node 13.14.0, node 12.18.4, 12.19.0, 12.19.1 show the error : ERR_PACKAGE_PATH_NOT_EXPORTED
  • With node 12.20.0, node 14.17.4, the error is not thrown.

The issue is that a new system for exports has been created, as defined here :

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

This feature allows to define the allowed requires that are possible in a package using globs, like this :

  "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/*"
  },

The pull request for this feature can be found here : https://github.com/nodejs/modules/issues/535

Now if you include a package that uses this new "glob" feature in the exports file, it can fail if you require that specific file.

Amarillas answered 10/8, 2021 at 15:52 Comment(4)
Some more info at nodejs.org/api/packages.html#subpath-importsTiernan
Yes, it worked using node version 12.20.0 and my old not working version was v12.18.2, thanks a lot.Delapaz
Node.js sounds like a "stable", "consistent", "user friendly" system. It's not a rocket science to introduce this feature while preserving basic backward compatibility. But it's too much to expect of Node.js.Puto
@DraganOkanovic If I had to write an incomprehensible documentation, I could not have done a better job than the Node documentation team. But it must be admitted that they also unnecessarily try to reinvent the wheel and create a convoluted system that is hard to explain even with a good documentation.Puto
A
10

Quick Fix:

For yarn

yarn upgrade

For npm

npm update
Annoyance answered 8/12, 2021 at 10:34 Comment(2)
yarn update did the job for me, thanksStrikebreaker
Yep, yep. this was the right solution for me. Thx.Deason
P
8

fixed by npm update && npm audit fix --force

Pernas answered 9/6, 2020 at 7:44 Comment(2)
This fixed my issue. I think the problem is with incompatible NextJS versions. This issue was happening when I cloned a NextJS tutorial project and tried to run npm run devDor
I had the same problem on my NextJS app as well. npm update --force fixed it.Avocado
L
4

UUID npm module was causing this error,

// const uuidv4 = require('uuid/v4'); // OLD
const { v4: uuidv4 } = require('uuid'); // NEW

removing node_modules, package-lock.json didn't help

Lunge answered 10/7, 2020 at 20:1 Comment(5)
This is not the correct answer to the question. You can start just commenting if you don't the answer yet.Vaticination
Well, I reached here for the same error and this is what solved my issue. Incase someone else face the same issue due to this cause might get help.Lunge
It's already answered here- #62549957Functionary
@paradocslover, thanks for pointing, sure enough that answer didn't comeup when I had the same problem.Lunge
I also got to this same SO answer with the same error.Ousel
C
2

I was facing a very similar issue: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/dima/Projects/project/node_modules/@babel/helper-compilation-targets/package.json.

I was trying to launch an older project and installed the last version of node 12 (which was used for the project initially): v12.22.12. I was hesitant to do major node version upgrade of the project for a small fix. But with this version, I was facing this error. After reading answer of edi9999, I tried to downgrade node to the precise node version used at that project during main development time: v12.13.0. And with this version everything worked well.

Seems like some babel package used internal node API, which was removed in the newer node 12 and therefore it became broken. So if you have a similar case, try to use precise node version of an old project.

Casillas answered 11/2, 2023 at 19:7 Comment(0)
J
2

As you can guess by all the answers this error is caused by packages incompatible with the installed npm version. Not always you will solve your problem by updating node, but sometimes you will need to downgrade it.

I had this problem with Jhipster, it wasn't working on lts, but worked on my workmate's machine wich had node v14.17.0. Here's how I did it (using nvm):

nvm install 14.17.0
nvm use 14.17.0

Replace 14.17.0 by the version you need to use the package causing the error.

Jeepers answered 8/3, 2023 at 13:17 Comment(0)
S
1

None of the answers worked for me, and after a bit digging I found the issue. There are some modules that are using Optimal Javascript Module Design So, with node upgrading you may start facing this error for those modules. In my case, I switched to node 18.x

For example I had the issue with graphql-upload module

So, instead of using:

import { graphqlUploadExpress } from 'graphql-upload';

I changed it to:

import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';

and the problem went away.

Smolt answered 23/3, 2023 at 20:20 Comment(0)
L
0

Fixed for me executing the following commands:

Upgrade Node.js:

nvm install 16
nvm use 16
node -v

Install yarn:

curl -o- -L https://yarnpkg.com/install.sh | bash
yarn -v

For yarn users:

rm yarn.lock
yarn install
Lais answered 8/11, 2021 at 4:59 Comment(2)
Please format the answer correctly and remove excessive header usageMouthpart
nvm install 16 nvm use 16 node -v fixed the issue for meGargle
M
0

I also faced a similar error. While trying to install a certain dependency. Turns out that the newer version of the dependency is not compatible with my node version (which was latest at the time). Downgrading the dependency fixed the issue for me.

Moise answered 12/5 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.