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 when building with a module for Edge Network services (cloudflare pages, vercel): RollupError: "toPath" is not exported. #24738

Closed
yabuking84 opened this issue Dec 14, 2023 · 6 comments

Comments

@yabuking84
Copy link

yabuking84 commented Dec 14, 2023

Environment

Working directory: /home/tawing-ubuntu/work/aceeagle/nuxt-tawing-supabase 5:50:11 AM
Nuxt project info: 5:50:11 AM


  • Operating System: Linux
  • Node Version: v20.10.0
  • Nuxt Version: 3.8.0
  • CLI Version: 3.10.0
  • Nitro Version: 2.7.0
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/megapossy/nuxt-tawing-supabase

Will work.

  • npm run dev:build -- --preset=vercel
  • npm run dev:build -- --preset=node-serve

Will have RollupError: "toPath" is not exported. errors

  • npm run dev:build -- --preset=vercel-edge
  • npm run dev:build -- --preset=cloudflare-pages

Describe the bug

Error Output:

✓ built in 643ms                                                                                                                                                                                         6:15:39 AM
✔ Server built in 656ms                                                                                                                                                                                    6:15:39 AM
✔ Generated public playground/.vercel/output/static                                                                                                                                                  nitro 6:15:39 AM
ℹ Building Nitro Server (preset: vercel-edge)                                                                                                                                                        nitro 6:15:39 AM

 ERROR  RollupError: "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".                                                                nitro 6:15:54 AM


6: import gitIgnore from 'ignore';
7: import slash from 'slash';
8: import {toPath} from 'unicorn-magic';
           ^
9: import {isNegativePattern} from './utilities.js';


 ERROR  "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".                                                                                   6:15:54 AM

  at error (node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
  at Module.error (node_modules/rollup/dist/es/shared/node-entry.js:13745:16)
  at Module.traceVariable (node_modules/rollup/dist/es/shared/node-entry.js:14175:29)
  at ModuleScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:12615:39)
  at ReturnValueScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
  at ChildScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
  at ReturnValueScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
  at ChildScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
  at Identifier.bind (node_modules/rollup/dist/es/shared/node-entry.js:8319:40)
  at CallExpression.bind (node_modules/rollup/dist/es/shared/node-entry.js:5892:23) 



 ERROR  "toPath" is not exported by "node_modules/unicorn-magic/default.js", imported by "node_modules/globby/ignore.js".        

Error occurs only if I preset nitro to edge rendering.

I created a module that is used on the nitro server only. Whenever I build a project using that module for edge rendering preset that error occurs., but no errors when building for a normal node server.

This module is using "@supabase/supabase-js"

Additional context

Tried to downgrade nitro and nuxt to 2.7.0 and 3.8.0 respectively as suggested in #24387.

Logs

No response

@Kjir
Copy link

Kjir commented Dec 18, 2023

This is due to globby: sindresorhus/globby#260

Unfortunately, due to the response of the package author, I doubt this will get fixed anytime soon: sindresorhus/unicorn-magic#1

Is this dependency really necessary?

@Kjir
Copy link

Kjir commented Dec 18, 2023

If, like me, you are using vite, here is a way to fix the issue. Update your vite.config.js and add:

    optimizeDeps: {
      exclude: ["@nuxt/kit"],
    }

Further details are explained here: storyblok/storyblok-nuxt#662

@danielroe
Copy link
Member

danielroe commented Dec 19, 2023

The issue here is that your code (or a module you use) is importing @nuxt/kit or module code. That can happen by adding it to optimizeDeps.include and should definitely never be done.

In this case it is here: https://github.com/megapossy/nuxt-tawing-supabase/blob/main/src/runtime/server/services/index.ts#L1

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@yabuking84
Copy link
Author

wow it works now. @nuxt/kit should not be imported. Thank you so much!

@nicogenz
Copy link

nicogenz commented Jan 4, 2024

@danielroe I quite dont understand the fix here? In the example, https://github.com/megapossy/nuxt-tawing-supabase/blob/main/src/runtime/server/services/index.ts#L1, its importing the logger from @nuxt/kit to log some messages. Are we not allowed to import nuxt/kit? For example if we want to log some message in a server api route, how would it look like?

@danielroe
Copy link
Member

You can log with console.log. Nuxt kit is meant to be used by modules (which run in node, and aren't runtime code). Any runtime code injected by modules should not import from Nuxt kit.

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

4 participants