Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error after upgrading to Nuxt 3.8.2: [ERROR] No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath" #24387

Closed
stefanobartoletti opened this issue Nov 21, 2023 · 30 comments

Comments

@stefanobartoletti
Copy link

stefanobartoletti commented Nov 21, 2023

Environment

Working directory: /home/stefano/Sviluppo/Personali/nuxt-storyblok-starter                                              12:05:18
Nuxt project info:                                                                                                      12:05:18

------------------------------
- Operating System: Linux
- Node Version:     v18.18.2
- Nuxt Version:     3.8.2
- CLI Version:      3.10.0
- Nitro Version:    2.8.0
- Package Manager:  pnpm@8.10.5
- Builder:          -
- User Config:      css, modules, extends, runtimeConfig, image, storyblok, tailwindcss, veeValidate, gtm, app, build
- Runtime Modules:  @storyblok/nuxt@5.7.7, @nuxtjs/tailwindcss@6.9.5, nuxt-icon@0.6.6, @vueuse/nuxt@10.6.1, @nuxt/image@1.1.0, @nuxt/devtools@1.0.3, @zadigetvoltaire/nuxt-gtm@0.0.13, @vee-validate/nuxt@4.11.8, @stefanobartoletti/nuxt-social-share@0.3.0
- Build Modules:    -
------------------------------

Reproduction

  • Update from previous version to Nuxt 3.8.2 by using npx nuxi upgrade --force
  • Run pnpm dev, the following error occurs
  • pnpm generate then pnpm preview does not seem to report any obvious error

Describe the bug

Error output:

✘ [ERROR] No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"

    node_modules/.pnpm/globby@14.0.0/node_modules/globby/ignore.js:8:8:
      8 │ import {toPath} from 'unicorn-magic';~~~~~~

✘ [ERROR] No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"

    node_modules/.pnpm/globby@14.0.0/node_modules/globby/index.js:7:8:
      7 │ import {toPath} from 'unicorn-magic';~~~~~~


 ERROR  [unhandledRejection] Build failed with 2 errors:                                                                11:53:08
node_modules/.pnpm/globby@14.0.0/node_modules/globby/ignore.js:8:8: ERROR: No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"
node_modules/.pnpm/globby@14.0.0/node_modules/globby/index.js:7:8: ERROR: No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"

  node_modules/.pnpm/globby@14.0.0/node_modules/globby/ignore.js:8:8: ERROR: No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"
  node_modules/.pnpm/globby@14.0.0/node_modules/globby/index.js:7:8: ERROR: No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath"
  at failureErrorWithLog (node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1649:15)
  at node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1058:25
  at node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1525:9
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Additional context

The error seems to originate in globby@14.0.0, in my lockfile this version is used only by:

  • @nuxt/kit@3.8.2
  • nitropack@2.8.0
  • nuxt@3.8.2

unicorn-magic@0.1.0 is present in my lockfile only as a dependency of globby@14.0.0

Logs

No response

@stefanobartoletti stefanobartoletti changed the title [ERROR] No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath" Error after upgrading to Nuxt 3.8.2: [ERROR] No matching export in "node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/default.js" for import "toPath" Nov 21, 2023
Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@jordypereira
Copy link

jordypereira commented Nov 21, 2023

We are having the same issue. I've been able to boil it down to the @storyblok/nuxt package.

And a reproduction:
https://stackblitz.com/~/github.com/jordypereira/nuxt-bug-globby-repro
https://github.com/jordypereira/nuxt-bug-globby-repro

@lammerfalcon
Copy link

lammerfalcon commented Nov 21, 2023

i have the same issue with storyblok and nuxt
downgrade doesn't work because nitro 2.8.0 supplied in all vesions above nuxt 3.3.3.
I tried different versions of nuxt starting from 3.4.0 and ending with 3.8.2 - all versions have a bug

@stefanobartoletti
Copy link
Author

stefanobartoletti commented Nov 21, 2023

Ok, updating only with npx nuxi upgrade (without the --force flag) and not recreating the lockfile does not fire the issue.

I tried to install a clean copy of Nuxt, and the problem still does not happen.

I suspect that it may be related to some module that maybe has not yet been updated to the 3.8.2 stack, so I think that I will wait some days to see if newer versions will solve it.

As things stands right now, it does not seem to be a problem strictly related to Nuxt, but if it is not a problem I would leave this open for now for reference, and try to take care of it in a few days.

@jordypereira @lammerfalcon thanks for your feedback, I am using Storyblok myself, thanks for pinpointing this.

Their module does not seem to have been updated to the 3.8.2 stack yet.

@lammerfalcon
Copy link

lammerfalcon commented Nov 21, 2023

I think that the error occurs because of the nitro version 2.8.0 and I don’t quite understand how to downgrade to version 2.7, it seems that nuxt 3.4.0 - 3.8.2 now always comes with 2.8.0. But for our project i need at least nuxt 3.7.0 version.

@lammerfalcon
Copy link

I found a quick solution
We need to downgrade nitro to 2.7 version... to do it - add following code into package.json
"overrides": {
"nitropack": "2.7.0"
}

@dhastings
Copy link

'globby' was updated to v14.0.0 a couple weeks back, which introduced an import for 'toPath' from the author's 'unicorn-magic' package, which has one release and no export named toPath. Seems like an error by the author maybe?

Globby v13.2.2 does not have that import, so overriding or using resolutions to set globby to v13.2.2 for the time being worked for me:

In package.json:

"resolutions": {
    "globby": "13.2.2"
}

@danielroe
Copy link
Member

toPath is only exported in node environments: https://unpkg.com/browse/unicorn-magic@0.1.0/node.js.

The issue here is that the storyblok module was pulling the module/build-time code into the runtime context by adding it to vite.optimizeDeps.include.

I've raised storyblok/storyblok-nuxt#662 which fixes the issue and should also speed up your dev server environment.

If anyone is experiencing this and isn't using @storyblok/nuxt, let me know. 🙏

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@stefanobartoletti
Copy link
Author

@danielroe thanks for your PR to fix the module!

@dhastings
Copy link

@danielroe Thanks for your help, much to learn!

@danielroe
Copy link
Member

Not at all! Your investigation was very helpful ❤️

@vladkuraev84
Copy link

vladkuraev84 commented Nov 25, 2023

toPath is only exported in node environments: https://unpkg.com/browse/unicorn-magic@0.1.0/node.js.

The issue here is that the storyblok module was pulling the module/build-time code into the runtime context by adding it to vite.optimizeDeps.include.

I've raised storyblok/storyblok-nuxt#662 which fixes the issue and should also speed up your dev server environment.

If anyone is experiencing this and isn't using @storyblok/nuxt, let me know. 🙏

unfortunately, I am not using @storyblok/nuxt, but have this problem in the build on the server. My package-lock.json does not have storyblok also. this also does not help(((: "overrides": { "nitropack": "2.7.0" }
package.json:
"devDependencies": { "@nuxt/devtools": "latest", "@nuxtjs/color-mode": "^3.3.2", "@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge", "nuxt": "^3.8.2", "nuxt-simple-sitemap": "^3.4.1", "sass": "^1.68.0", "vue": "^3.3.9", "vue-router": "^4.2.5", "wrangler": "^3.10.1" }, "dependencies": { "@nuxtjs/robots": "^3.0.0", "@pinia/nuxt": "^0.5.1", "axios": "^1.5.1", "pinia": "^2.1.7" }

I also tried to use "nuxt": "^3.3.3",

@boxexchanger
Copy link

sindresorhus/globby#260

@tchin25
Copy link

tchin25 commented Nov 28, 2023

I have this issue when building with Nitro's cloudflare-pages preset. With node-server it's fine.

Here are my dependencies

"devDependencies": {
"@nuxt/devtools": "latest",
"@nuxtjs/tailwindcss": "^6.10.1",
"@tailwindcss/typography": "^0.5.10",
"nuxt": "^3.8.2",
"nuxt-security": "^1.0.0-rc.4",
"vue": "^3.3.8",
"vue-router": "^4.2.5"
},
"dependencies": {
"@nuxt/content": "^2.9.0",
"@radix-icons/vue": "^1.0.0",
"@vueuse/core": "^10.6.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7"
},

@mohdlatif
Copy link

I am using Nuxt 3.8.2 with nitro 2.8.0

Using also Prismic as headless.

The website is hosted on Vercel and works fine
However, when deploying to CloudFlare I get this issue

16:58:34.147 | [success] [nitro] Generated public dist
-- | --
16:58:34.185 | [info] [nitro] Building Nitro Server (preset: `cloudflare-pages`)
16:58:50.786 | [error] [nitro] RollupError: "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".
16:58:50.787 |  
16:58:50.787 |  
16:58:50.787 | 6: import gitIgnore from 'ignore';
16:58:50.788 | 7: import slash from 'slash';
16:58:50.788 | 8: import {toPath} from 'unicorn-magic';
16:58:50.788 | ^
16:58:50.788 | 9: import {isNegativePattern} from './utilities.js';
16:58:50.789 | [error] "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".
16:58:50.789 | at error (node_modules/nitropack/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
16:58:50.789 | at Module.error (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:12728:16)
16:58:50.790 | at Module.traceVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:13169:29)
16:58:50.790 | at ModuleScope.findVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:11582:39)
16:58:50.790 | at ReturnValueScope.findVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:5897:38)
16:58:50.790 | at FunctionBodyScope.findVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:5897:38)
16:58:50.790 | at ReturnValueScope.findVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:5897:38)
16:58:50.790 | at FunctionBodyScope.findVariable (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:5897:38)
16:58:50.791 | at Identifier.bind (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:7184:40)
16:58:50.791 | at CallExpression.bind (node_modules/nitropack/node_modules/rollup/dist/es/shared/node-entry.js:4625:23)
16:58:50.791 |  
16:58:50.792 | [error] "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".
16:58:50.899 | Failed: Error while executing user command. Exited with error code: 1
16:58:50.909 | Failed: build command exited with code: 1
16:58:51.901 | Failed: error occurred while running build command


@danielroe
Copy link
Member

danielroe commented Nov 28, 2023

If you can provide a minimal reproduction, we can have a look 🙏

@boxexchanger
Copy link

Hi @danielroe
Just to install nuxt clear project then try to build project for CF

NITRO_PRESET=cloudflare-pages nuxt build

Problem is globby updated to 14.0.0 and toPath not exported for non-node project
modules nuxt, nuxt/kit etc.. using globby 14.0.0 when i try downgrade version it can be fixed for nuxt but nuxt/kit install globby 14 =(

Refs:
sindresorhus/unicorn-magic#1
sindresorhus/globby#260

Copy link
Member

danielroe commented Nov 28, 2023

That does not reproduce the issue.

(This issue should only occur when you are importing @nuxt/kit or another build-time dependency within your runtime code.)

@boxexchanger
Copy link

@danielroe Hi sorry so much:
Preview https://stackblitz.com/edit/github-jfmbya?file=package.json

in terminal try please

NITRO_PRESET=cloudflare-pages nuxt build

@boxexchanger
Copy link

I'm sorry! I have find hot to resolve problem "nuxt-simple-sitemap": "^3.4.1", must be updated to "4.1.6"
so issue now is closed but will be better to have a more clear stacktrace to understand problem without remove module by module this stack said problem in globby with using in nuxt.

@tchin25
Copy link

tchin25 commented Nov 28, 2023

Thanks @boxexchanger for all your troubleshooting. For me, it was caused by nuxt-security and I had to downgrade from 1.0.0-rc.4 to 0.14.4

@imm
Copy link

imm commented Nov 28, 2023

@danielroe can you please take a look.

I'm working on a module for Nuxt that uses globby. The same error occurs.

The minimal reproduction:

  1. Use Nuxt starter for module
  2. Import globby in src/module.ts
  3. Use it somewhere in setup
  4. Run pnpm prepack (or npm run prepack)

You may try it here:
https://stackblitz.com/edit/github-sthtzm?file=src%2Fmodule.ts

This error is completely confusing, since my module as part of the Nuxt project (inside the modules directory) works without any problems. What am I doing wrong?

@danielroe
Copy link
Member

@imm That is caused by the fact that you have several different versions of globby installed but you haven't declared a dependency on globby in your package.json. Once you run npm i globby you should be fine.

@imm
Copy link

imm commented Nov 29, 2023

@danielroe Thank you very much!

@bootsmann1995
Copy link

I'm getthing this error after ugrading nuxt 3.8.1 to nuxt 3.9.2

is there something i need to include in vite.optimizeDeps or is there a way to debug if i have a package that needs another version of a dependency?

X [ERROR] No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
    ../../node_modules/globby/ignore.js:8:8:
      8 │ import {toPath} from 'unicorn-magic';
        ╵         ~~~~~~
X [ERROR] No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
    ../../node_modules/globby/index.js:7:8:
      7 │ import {toPath} from 'unicorn-magic';
        ╵         ~~~~~~
 ERROR  [unhandledRejection] Build failed with 2 errors:
../../node_modules/globby/ignore.js:8:8: ERROR: No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
../../node_modules/globby/index.js:7:8: ERROR: No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
  ../../node_modules/globby/ignore.js:8:8: ERROR: No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
  ../../node_modules/globby/index.js:7:8: ERROR: No matching export in "../../node_modules/unicorn-magic/default.js" for import "toPath"
  at failureErrorWithLog (C:\LAIT\scanpipe-frontend-new\src\node_modules\esbuild\lib\main.js:1651:15)
  at C:\LAIT\scanpipe-frontend-new\src\node_modules\esbuild\lib\main.js:1059:25
  at C:\LAIT\scanpipe-frontend-new\src\node_modules\esbuild\lib\main.js:1527:9
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@bootsmann1995
Copy link

fixed this by adding "globby" to build.transpile.

@snakysnake
Copy link

I am also facing the same issue, super unclear to me where it comes from. Trying to figure out whats wrong here. Super complicated.

@danielroe
Copy link
Member

This comes from wrongly importing nuxt/kit in your runtime Nuxt app. (It's only meant for use in modules or your Nuxt config file.)

Likely the issue is a module you are using which is using useLogger or similar in the runtime code they inject.

@DenisLug
Copy link
Contributor

I encountered the same issue and migrated my module to Nuxt Layers. It wasn't that complicated and fits in my opinion much better into the embedding application. Perhaps this could be a fallback for some here.

@snakysnake
Copy link

snakysnake commented Feb 14, 2024

Thank you for the quick answers, guys! In my case it became complicated as I (due to other reasons) did not update all my packages for a while and they are of course dependent to each other.
If someone has a similar issue

  1. Make sure all imports are still relevant - remove packages that can be removed
  2. Always commit before upgrading your packages, so you can revert your changes

In my case, the issue (pretty certain) came from '@vite-pwa/nuxt', but it was very hard to pinpoint and still im only 90% sure, not 100%, but after removing this package, the error disappeared.
I upgraded from nuxt3.4 and another error I got was due to the autoimports changing with pinia, instead of:

//nuxt.config.js / .ts
 modules: [
    ['@pinia/nuxt',
      { autoImports: ['defineStore', 'mapStores'] }
]

defineStore will be autoimported anyways so just register the autoimports as follows:

//nuxt.config.js / .ts
  imports: {
    presets: [
      {
        from: "pinia",
        imports: ["mapStores"]
      }
    ],
  },

Maybe it's relevant for someone, it was hard to find online by googling so, just for keywords sake: [mapStores issue nuxt pinia mapStores not defined]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests