Nuxt 3 Deploy Failed: Rollup failed to resolve import "vue"

Hi all,

I’ve been trying to deploy a Nuxt 3 app for the past few hours, but all attempts are failing. The app runs well locally using pnpm as the package manager.

I’ve tried clearing the cache, redeploying, updating dependencies, etc. But, nothing gives.

No public URL is yet available as the site isn’t deployed. But I’ll share the error log and all other relevant information.

In a nutshell, the build is failing at the following line:

8:59:38 AM: [error] [vite]: Rollup failed to resolve import "vue" from "node_modules/.pnpm/nuxt@3.0.0-rc.11/node_modules/nuxt/dist/app/entry.mjs".

Here’s my stripped package.json file:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "@nuxt/content": "^2.1.1",
    "@nuxt/image-edge": "1.0.0-27719579.87dcdf2",
    "@types/google.maps": "^3.50.0",
    "nuxt": "3.0.0-rc.11",
    "nuxt-schema-org": "1.1.0-beta.4",
    "nuxt-windicss": "^2.5.0",
    "sitemap": "^7.1.1"
  },
  "dependencies": {
    "@sendgrid/mail": "^7.7.0",
    "@skjnldsv/vue-plyr": "^7.3.0",
    "@types/ua-parser-js": "^0.7.36",
    "@vueuse/core": "^9.1.1",
    "animate.css": "^4.1.1",
    "firebase": "^9.12.1",
    "firebase-admin": "^11.1.0",
    "friendly-challenge": "^0.9.5",
    "install": "^0.13.0",
    "lite-youtube-embed": "^0.2.0",
    "safe-json-stringify": "^1.2.0",
    "short-unique-id": "^4.4.4",
    "twemoji": "^14.0.2",
    "ua-parser-js": "^1.0.2",
    "v-use-places-autocomplete": "^1.0.1",
    "vue3-lottie": "^2.3.0"
  }
}

And the build output log:

8:59:07 AM: Build ready to start
8:59:08 AM: build-image version: d05976bd3309b73a86eaa327bf80e105ff13f5e4 (focal)
8:59:08 AM: build-image tag: v4.13.0
8:59:08 AM: buildbot version: 3a000de5d3727998f3297394596d287d7e49aecd
8:59:08 AM: Building without cache
8:59:08 AM: Starting to prepare the repo for build
8:59:09 AM: No cached dependencies found. Cloning fresh repo
8:59:09 AM: git clone https://github.com/treighmawaka/energycrew-site
8:59:10 AM: Preparing Git Reference refs/heads/main
8:59:11 AM: Parsing package.json dependencies
8:59:12 AM: Starting build script
8:59:12 AM: Installing dependencies
8:59:12 AM: Python version set to 2.7
8:59:12 AM: v16.18.0 is already installed.
8:59:13 AM: Now using node v16.18.0 (npm v8.19.2)
8:59:13 AM: Enabling node corepack
8:59:13 AM: Started restoring cached build plugins
8:59:13 AM: Finished restoring cached build plugins
8:59:13 AM: Attempting ruby version 2.7.2, read from environment
8:59:13 AM: Using ruby version 2.7.2
8:59:14 AM: Using PHP version 8.0
8:59:14 AM: No pnpm workspaces detected
8:59:14 AM: Started restoring cached node modules
8:59:14 AM: Finished restoring cached node modules
8:59:14 AM: Installing NPM modules using PNPM version 7.13.4
8:59:15 AM: Lockfile is up to date, resolution step is skipped
8:59:15 AM: Progress: resolved 1, reused 0, downloaded 0, added 0
8:59:15 AM: Packages: +1007
8:59:15 AM: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8:59:15 AM: Packages are hard linked from the content-addressable store to the virtual store.
8:59:15 AM:   Content-addressable store is at: /opt/build/.pnpm-store/v3
8:59:15 AM:   Virtual store is at:             node_modules/.pnpm
8:59:16 AM: Progress: resolved 1007, reused 0, downloaded 22, added 21
8:59:17 AM: Progress: resolved 1007, reused 0, downloaded 88, added 84
8:59:18 AM: Progress: resolved 1007, reused 0, downloaded 215, added 217
8:59:19 AM: Progress: resolved 1007, reused 0, downloaded 298, added 302
8:59:20 AM: Progress: resolved 1007, reused 0, downloaded 420, added 423
8:59:21 AM: Progress: resolved 1007, reused 0, downloaded 603, added 603
8:59:22 AM: Progress: resolved 1007, reused 0, downloaded 708, added 709
8:59:23 AM: Progress: resolved 1007, reused 0, downloaded 824, added 824
8:59:24 AM: Progress: resolved 1007, reused 0, downloaded 1001, added 1006
8:59:25 AM: Progress: resolved 1007, reused 0, downloaded 1002, added 1007, done
8:59:25 AM: .../node_modules/core-js-pure postinstall$ node -e "try{require('./postinstall')}catch(e){}"
8:59:25 AM: .../core-js@3.25.2/node_modules/core-js postinstall$ node -e "try{require('./postinstall')}catch(e){}"
8:59:25 AM: .../node_modules/protobufjs postinstall$ node scripts/postinstall
8:59:25 AM: .../node_modules/protobufjs postinstall$ node scripts/postinstall
8:59:25 AM: .../node_modules/core-js-pure postinstall: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
8:59:25 AM: .../node_modules/core-js-pure postinstall: The project needs your help! Please consider supporting of core-js:
8:59:25 AM: .../node_modules/core-js-pure postinstall: > https://opencollective.com/core-js
8:59:25 AM: .../node_modules/core-js-pure postinstall: > https://patreon.com/zloirock
8:59:25 AM: .../node_modules/core-js-pure postinstall: > bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz
8:59:25 AM: .../node_modules/core-js-pure postinstall: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
8:59:25 AM: .../node_modules/core-js-pure postinstall: Done
8:59:25 AM: .../core-js@3.25.2/node_modules/core-js postinstall: Done
8:59:25 AM: .../node_modules/protobufjs postinstall: Done
8:59:25 AM: .../node_modules/protobufjs postinstall: Done
8:59:25 AM: .../sharp@0.30.7/node_modules/sharp install$ (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
8:59:26 AM: .../node_modules/vue-demi postinstall$ node ./scripts/postinstall.js
8:59:26 AM: .../node_modules/vue-demi postinstall$ node ./scripts/postinstall.js
8:59:26 AM: .../node_modules/vue-demi postinstall$ node ./scripts/postinstall.js
8:59:26 AM: .../node_modules/vue-demi postinstall: Done
8:59:26 AM: .../node_modules/vue-demi postinstall: Done
8:59:26 AM: .../node_modules/vue-demi postinstall: Done
8:59:26 AM: .../sharp@0.30.7/node_modules/sharp install: sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.12.2/libvips-8.12.2-linux-x64.tar.br
8:59:27 AM: .../sharp@0.30.7/node_modules/sharp install: sharp: Integrity check passed for linux-x64
8:59:27 AM: .../sharp@0.30.7/node_modules/sharp install: Done
8:59:27 AM: .../esbuild@0.15.9/node_modules/esbuild postinstall$ node install.js
8:59:27 AM: .../esbuild@0.15.9/node_modules/esbuild postinstall: Done
8:59:28 AM: dependencies:
8:59:28 AM: + @sendgrid/mail 7.7.0
8:59:28 AM: + @skjnldsv/vue-plyr 7.3.0
8:59:28 AM: + @types/ua-parser-js 0.7.36
8:59:28 AM: + @vueuse/core 9.2.0
8:59:28 AM: + animate.css 4.1.1
8:59:28 AM: + firebase 9.12.1
8:59:28 AM: + firebase-admin 11.1.0
8:59:28 AM: + friendly-challenge 0.9.7
8:59:28 AM: + install 0.13.0
8:59:28 AM: + lite-youtube-embed 0.2.0
8:59:28 AM: + safe-json-stringify 1.2.0
8:59:28 AM: + short-unique-id 4.4.4
8:59:28 AM: + twemoji 14.0.2
8:59:28 AM: + ua-parser-js 1.0.2
8:59:28 AM: + v-use-places-autocomplete 1.0.1
8:59:28 AM: + vue3-lottie 2.3.0
8:59:28 AM: devDependencies:
8:59:28 AM: + @nuxt/content 2.1.1
8:59:28 AM: + @nuxt/image-edge 1.0.0-27719579.87dcdf2
8:59:28 AM: + @types/google.maps 3.50.2
8:59:28 AM: + nuxt 3.0.0-rc.11
8:59:28 AM: + nuxt-schema-org 1.1.0-beta.4
8:59:28 AM: + nuxt-windicss 2.5.2
8:59:28 AM: + sitemap 7.1.1
8:59:28 AM: Done in 13.2s
8:59:28 AM: NPM modules installed using PNPM
8:59:28 AM: Started restoring cached go cache
8:59:28 AM: Finished restoring cached go cache
8:59:28 AM: Installing Go version 1.17 (requested 1.17)
8:59:32 AM: unset GOOS;
8:59:32 AM: unset GOARCH;
8:59:32 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
8:59:32 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
8:59:32 AM: go version >&2;
8:59:32 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
8:59:32 AM: go version go1.17 linux/amd64
8:59:32 AM: Installing missing commands
8:59:32 AM: Verify run directory
8:59:34 AM: ​
8:59:34 AM: ────────────────────────────────────────────────────────────────
8:59:34 AM:   Netlify Build                                                 
8:59:34 AM: ────────────────────────────────────────────────────────────────
8:59:34 AM: ​
8:59:34 AM: ❯ Version
8:59:34 AM:   @netlify/build 27.20.6
8:59:34 AM: ​
8:59:34 AM: ❯ Flags
8:59:34 AM:   baseRelDir: true
8:59:34 AM:   buildId: 634ff49bb6f18f0358e48b27
8:59:34 AM:   deployId: 634ff49bb6f18f0358e48b29
8:59:34 AM: ​
8:59:34 AM: ❯ Current directory
8:59:34 AM:   /opt/build/repo
8:59:34 AM: ​
8:59:34 AM: ❯ Config file
8:59:34 AM:   No config file was defined: using default values.
8:59:34 AM: ​
8:59:34 AM: ❯ Context
8:59:34 AM:   production
8:59:34 AM: ​
8:59:34 AM: ────────────────────────────────────────────────────────────────
8:59:34 AM:   1. Build command from Netlify app                             
8:59:34 AM: ────────────────────────────────────────────────────────────────
8:59:34 AM: ​
8:59:34 AM: $ npm run build
8:59:34 AM: > build
8:59:34 AM: > nuxt build
8:59:34 AM: [log] Nuxi 3.0.0-rc.11
8:59:34 AM: [log] Nuxt 3.0.0-rc.11 with Nitro 0.5.4
8:59:37 AM: [success] [@nuxt/content] Using `~/components/content` for components in Markdown
8:59:38 AM: [error] [vite]: Rollup failed to resolve import "vue" from "node_modules/.pnpm/nuxt@3.0.0-rc.11/node_modules/nuxt/dist/app/entry.mjs".
8:59:38 AM: This is most likely unintended because it can break your application at runtime.
8:59:38 AM: If you do want to externalize this module explicitly add it to
8:59:38 AM: `build.rollupOptions.external`
8:59:38 AM: [error] [vite]: Rollup failed to resolve import "vue" from "node_modules/.pnpm/nuxt@3.0.0-rc.11/node_modules/nuxt/dist/app/entry.mjs".
8:59:38 AM: This is most likely unintended because it can break your application at runtime.
8:59:38 AM: If you do want to externalize this module explicitly add it to
8:59:38 AM: `build.rollupOptions.external`
8:59:38 AM:   This is most likely unintended because it can break your application at runtime.
8:59:38 AM:   If you do want to externalize this module explicitly add it to
8:59:38 AM:   `build.rollupOptions.external`
8:59:38 AM:   at onRollupWarning (node_modules/.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:45907:19)
8:59:38 AM:   at onwarn (node_modules/.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:45705:13)
8:59:38 AM:   at Object.onwarn (node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:23225:13)
8:59:38 AM:   at ModuleLoader.handleResolveId (node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:22352:26)
8:59:38 AM:   at node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:22313:26
8:59:38 AM: ​
8:59:38 AM: ────────────────────────────────────────────────────────────────
8:59:38 AM:   "build.command" failed                                        
8:59:38 AM: ────────────────────────────────────────────────────────────────
8:59:38 AM: ​
8:59:38 AM:   Error message
8:59:38 AM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
8:59:38 AM: ​
8:59:38 AM:   Error location
8:59:38 AM:   In Build command from Netlify app:
8:59:38 AM:   npm run build
8:59:38 AM: ​
8:59:38 AM:   Resolved config
8:59:38 AM:   build:
8:59:38 AM:     command: npm run build
8:59:38 AM:     commandOrigin: ui
8:59:38 AM:     environment:
8:59:38 AM:       - CI
8:59:38 AM:       - FIREBASE_API_KEY
8:59:38 AM:       - FIREBASE_APP_ID
8:59:38 AM:       - FIREBASE_AUTH_DOMAIN
8:59:38 AM:       - FIREBASE_MEASUREMENT_ID
8:59:38 AM:       - FIREBASE_MESSAGING_SENDER_ID
8:59:38 AM:       - FIREBASE_PROJECT_ID
8:59:38 AM:       - FIREBASE_STORAGE_BUCKET
8:59:38 AM:       - FRIENDLY_CAPTCHA_API_KEY
8:59:38 AM:       - FRIENDLY_CAPTCHA_SITE_KEY
8:59:38 AM:       - GOOGLE_PLACES_API_KEY
8:59:38 AM:       - SENDGRID_API_KEY
8:59:38 AM:       - SENDGRID_BOOKING_REQUEST_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_BOOKING_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_CONTACT_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_QUOTE_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_REMIDER_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_REQUEST_TEMPLATE_ID
8:59:38 AM:       - SENDGRID_REVIEW_TEMPLATE_ID
8:59:38 AM:     publish: /opt/build/repo/dist
8:59:38 AM:     publishOrigin: ui
8:59:38 AM: Caching artifacts
8:59:38 AM: Started saving node modules
8:59:38 AM: Finished saving node modules
8:59:38 AM: Started saving build plugins
8:59:38 AM: Finished saving build plugins
8:59:38 AM: Started saving pip cache
8:59:38 AM: Finished saving pip cache
8:59:38 AM: Started saving emacs cask dependencies
8:59:38 AM: Finished saving emacs cask dependencies
8:59:38 AM: Started saving maven dependencies
8:59:38 AM: Finished saving maven dependencies
8:59:38 AM: Started saving boot dependencies
8:59:38 AM: Finished saving boot dependencies
8:59:38 AM: Started saving rust rustup cache
8:59:38 AM: Finished saving rust rustup cache
8:59:38 AM: Started saving go dependencies
8:59:38 AM: Finished saving go dependencies
8:59:39 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
8:59:39 AM: Creating deploy upload records
8:59:40 AM: Failing build: Failed to build site
8:59:40 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
8:59:40 AM: Finished processing build request in 31.601942915s

I’d appreciate any help. Thanks in advance.

2 Likes

Hey there, @treigh :wave:

Thanks for reaching out. In order to debug this, can you try reproducing this without pnpm? For example, does the issue persist if you use npm?

Please share the reproduction with us so that we can see more details about where this is occurring.

Thanks!

1 Like

Thanks for chiming in, @hillary. I switched to NPM and though things still work well locally, I’m faced with two random errors, causing the build to fail. I’ve fixed the first one (missing the Sass loader), but I’m not having much luck with the second.

12:51:26 PM: [error] 'default' is not exported by node_modules/lite-youtube-embed/src/lite-yt-embed.js, imported by plugins/youtube.client.js

This is occurring in a Nuxt 3 custom client plugin that works just fine locally.

// plugins/youtube.client.js
import { defineNuxtPlugin } from "#app";
import youtube from "lite-youtube-embed"; // 👈 the build is failing at this import line

export default defineNuxtPlugin((nuxtApp) => {
	nuxtApp.provide("youtube", youtube);
});

Any thoughts?

@hillary I managed to fix this by removing the faulty dependency. In the end, switching from pnpm to npm was the ultimate fix. I appreciate your help.

Hey there! I am glad to hear that you are unblocked. I’ll also surface this to the team working on pnpm so that they know you encountered an obstacle.

Happy building :rocket:

1 Like

@treigh quick question when you’ve ported the project from npm to pnpm have you used the pnpm import feature?

To investigate a little bit further could you please link here your deploy url? So that we can check some internal metrics?

By the way if I use your package.json in a project and just run pnpm install on it I get a peer dependency error:

Hello @lukas.holzer,
I’m having a very similar issue since netlify supported pnpm. My site is built from the begining with pnpm and it worked and built fine until 2 days ago.

[vite]: Rollup failed to resolve import "js-cookie" from "virtual:nuxt:/opt/build/repo/.nuxt/i18n.internal.mjs".
9:36:45 AM: This is most likely unintended because it can break your application at runtime.
9:36:45 AM: If you do want to externalize this module explicitly add it to
9:36:45 AM: `build.rollupOptions.external`

For the peer dependency issue, there is a config for pnpm that will install peer dependencies which I assume @treigh has turned on like I do, so that can’t be related.

@ramiejleh and @treigh can you maybe tell me which pnpm version are you using locally?

I think it’s that you need to run your pnpm install with --shamefully-hoist so I’ve created a PR to add this feature of PNPM_FLAGS environment variable.

similar to: Build environment variables | Netlify Docs

2 Likes

Just go to that conclusion 30mins ago! Thank you for creating the PR! @lukas.holzer

How long would it be until this takes effect? I can see the PR is already merged :netliconfetti:

Hi folks

We’ve merged the recent PR on our build pipelines, can you try to run the builds now?

Do not forget to add the --shamefully-hoist flag in your pnpm install command by using the PNPM_FLAGS environment variable.

If you need anything else let us know!

1 Like

Hi @lukas.holzer to move to npm, I simply removed the pnpm-lock.yaml file, deleted node_modules and pushed the changes to trigger a new deploy. I didn’t use the pnpm import feature.

The site is live now, on a custom domain, but you can track it internally with under wondrous-snickerdoodle-14e8ea. I deleted those failed deploys to tidy up a bit.

Oh I thought like the other direction that you maybe converted to pnpm from npm and therefore it was failing, due to some lock-file mismatch if it was generated by a different package manager.

But I think you are using a nuxt site which should be the same issue as for @ramiejleh
Some frameworks like Nuxt have some known issues that you can only workaround with pnpm by providing the extra installation option --shamefully-hoist which will create a flat node_modules structure similar to npm or yarn even-though it is highly discouraged by pnpm, it’s the only way to get it working.You can specify this additional flags by leveraging the environment variable PNPM_FLAGS to provide this command to your pnpm install command.

2 Likes

It makes sense. I’m glad this is noted now and hopefully, it’ll be helpful for anyone else facing this.

1 Like

Hello @gualter @lukas.holzer I am facing the same error.

9:33:12 AM: ────────────────────────────────────────────────────────────────
9:33:12 AM:   1. Build command from Netlify app                             
9:33:12 AM: ────────────────────────────────────────────────────────────────
9:33:12 AM: ​
9:33:12 AM: $ yarn run build
9:33:12 AM: yarn run v1.22.19
9:33:12 AM: $ nuxt build
9:33:12 AM: [log] Nuxi 3.0.0-rc.12
9:33:12 AM: [log] Nuxt 3.0.0-rc.12 with Nitro 0.6.0
9:33:14 AM: [error] [vite]: Rollup failed to resolve import "vue" from "node_modules/.pnpm/nuxt@3.0.0-rc.12/node_modules/nuxt/dist/app/entry.mjs".
9:33:14 AM: This is most likely unintended because it can break your application at runtime.
9:33:14 AM: If you do want to externalize this module explicitly add it to
9:33:14 AM: `build.rollupOptions.external`
9:33:14 AM: [error] [vite]: Rollup failed to resolve import "vue" from "node_modules/.pnpm/nuxt@3.0.0-rc.12/node_modules/nuxt/dist/app/entry.mjs".
9:33:14 AM: This is most likely unintended because it can break your application at runtime.
9:33:14 AM: If you do want to externalize this module explicitly add it to
9:33:14 AM: `build.rollupOptions.external`
9:33:14 AM:   This is most likely unintended because it can break your application at runtime.
9:33:14 AM:   If you do want to externalize this module explicitly add it to
9:33:14 AM:   `build.rollupOptions.external`

Could you please explain me how to add the --shamefully-hoist flag?
I can run this flag with pnpm install on my local computer, but in Netlify I just can see that I can edit in the build settings the build command and inside the build it does not work. Locally I use the --shamefully-hoist for installing the node_modules packages, but not for building the deploy version

Thank you

Hi @Bernardao

You need to set the environment variable PNPM_FLAGS to the value of your flags for them to be considered during the install process:

Hope this helps!

Do you mean like this?
I added the value of --shamefully-hoist to the *****

I can’t understand at 100% how to set it to the install

Yes, does that not work?

Yes it worked :slight_smile:
Thank you