78

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
> 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)

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?

Simon
  • 1,280
  • 3
  • 10
  • 21

11 Answers11

100

Using npm update fixed the same error for me.

paradocslover
  • 2,932
  • 3
  • 18
  • 44
Harsha Vardhan Chakka
  • 1,357
  • 1
  • 9
  • 7
  • 1
    An update of `@babel/` modules is enough. Worked for me and for [some open source](https://github.com/americanexpress/holocron/pull/35/) too. – ilyazub May 19 '21 at 12:08
  • This fixed the issue for me, and I had it with discord.js. – diggity Nov 29 '21 at 13:50
  • 4
    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). – rapt Nov 06 '22 at 11:11
  • Any reason why it occurred? and how this command fix the issue – VishalParkash Jan 13 '23 at 07:30
58

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

Arnab Rahman
  • 1,003
  • 1
  • 9
  • 15
24

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
Rohman HM
  • 2,539
  • 3
  • 25
  • 40
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.

edi9999
  • 19,701
  • 13
  • 88
  • 127
  • Some more info at https://nodejs.org/api/packages.html#subpath-imports – Dragan Okanovic Feb 27 '22 at 12:02
  • Yes, it worked using node version 12.20.0 and my old not working version was v12.18.2, thanks a lot. – Weam Adel Jul 26 '22 at 14:50
  • 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. – rapt Nov 06 '22 at 11:37
  • @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. – rapt Nov 06 '22 at 11:51
8

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

Simon
  • 1,280
  • 3
  • 10
  • 21
  • 1
    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 dev – Africanfruit Dec 27 '21 at 18:29
  • I had the same problem on my NextJS app as well. `npm update --force` fixed it. – Abhik Banerjee Feb 15 '22 at 18:37
7

Quick Fix:

For yarn

yarn upgrade

For npm

npm update
Byusa
  • 2,279
  • 1
  • 16
  • 21
5

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

JBB
  • 317
  • 1
  • 9
  • This is not the correct answer to the question. You can start just commenting if you don't the answer yet. – Rohman HM Sep 01 '20 at 12:46
  • 2
    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. – JBB Sep 08 '20 at 23:41
  • It's already answered here- https://stackoverflow.com/questions/62549457/error-err-package-path-not-exported-package-subpath-v4-is-not-defined-by – paradocslover Nov 10 '20 at 08:23
  • @paradocslover, thanks for pointing, sure enough that answer didn't comeup when I had the same problem. – JBB Feb 06 '21 at 07:20
  • 1
    I also got to this same SO answer with the same error. – mike james Oct 27 '21 at 07:00
1

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.

DimaDK
  • 49
  • 2
  • 3
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.

Kostanos
  • 9,615
  • 4
  • 51
  • 65
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
John Difool
  • 5,572
  • 5
  • 45
  • 80
0

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.

emolano
  • 13
  • 2