'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /app/node_modules/@babel/helper-compilation-targets/package.json
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?
Solution 1:[1]
Using npm update
fixed the same error for me.
Solution 2:[2]
I had the similar problem. npm install @babel/helper-compilation-targets --save-dev
solved this situation
Solution 3:[3]
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.
- Removing the lock file. In this case I'm using
yarn
so I need to delete theyarn.lock
file. If you're usingnpm
the lock file ispackage-lock.json
.
# for yarn user
rm yarn.lock
# for npm user
rm package-lock.json
- And then I reinstall all the dependencies.
# for yarn user
yarn install
# for npm user
npm install
Solution 4:[4]
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.
Solution 5:[5]
fixed by npm update && npm audit fix --force
Solution 6:[6]
UUID npm module was causing this error,
// const uuidv4 = require('uuid/v4'); // OLD
const { v4: uuidv4 } = require('uuid'); // NEW
removing node_modules, package-lock.josn didn't help
Solution 7:[7]
Quick Fix:
For yarn
yarn upgrade
For npm
npm update
Solution 8:[8]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | paradocslover |
Solution 2 | Arnab Rahman |
Solution 3 | Rohman HM |
Solution 4 | edi9999 |
Solution 5 | Simon |
Solution 6 | JBB |
Solution 7 | Byusa |
Solution 8 | John Difool |