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

@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

Another suggestion that is probably an even better option is to put this in netlify.toml file, as it is not a “secret variable” and as this step can be easily omitted in case you have to set up a site again.

[build.environment]
PNPM_FLAGS = "--shamefully-hoist"
1 Like

To follow up on this thread, we’ve updated the Nuxt on Netlify documentation to clarify this going forward. Thank you for reporting your concerns.

1 Like

That’s great!

It’s also worth noting that Nuxt 3 now recommends adding an .npmrc file with shamefully-hoist=true for pnpm deployments.

1 Like