Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Exports is undefined in dev if add "next" to transpilePackages #58114

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

Closed
1 task done
Noitidart opened this issue Nov 7, 2023 · 5 comments
Closed
1 task done

Exports is undefined in dev if add "next" to transpilePackages #58114

Noitidart opened this issue Nov 7, 2023 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@Noitidart
Copy link

Noitidart commented Nov 7, 2023

Link to the code that reproduces this issue

https://github.com/Noitidart/self-transpile

To Reproduce

  1. Using { node: 'v18.13.0', npm: '8.19.3' }
  2. Run npx create-next-app@latest
  3. Accept all defaults except for "App Router" choose no (this may not matter).
  4. Once complete, go to package.json and add "browserslist": ["supports es5"]
  5. Go to next.config.js and add transpilePackages: ['next']
  6. Do npm run dev.
  7. You will see page errors with "exports is not defined"

Current vs. Expected behavior

Dev should work.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
Binaries:
  Node: 18.13.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.2-canary.17
  eslint-config-next: 14.0.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC transpilation

Additional context

No response

@Noitidart Noitidart added the bug Issue was opened via the bug report template. label Nov 7, 2023
@github-actions github-actions bot added the SWC Related to minification/transpilation in Next.js. label Nov 7, 2023
@Noitidart
Copy link
Author

I think it was my mistake, it works now, but I'm using 14.0.2

@Noitidart Noitidart reopened this Nov 15, 2023
@Noitidart
Copy link
Author

Actually it exists, but its a different bug. Its a bug in dev. Updating it now, when "next" is in the list, we get "Exports is not defined"

@Noitidart Noitidart changed the title Cannot transpile next 14.0.1 to ES5 and cannot add "next" to transpilePackages Exports is undefined in dev if add "next" to transpilePackages Nov 15, 2023
@kdy1 kdy1 removed the SWC Related to minification/transpilation in Next.js. label Jan 30, 2024
@kdy1
Copy link
Member

kdy1 commented Jan 30, 2024

Investigation

  • This still happens on Next.js 14.1.1-canary.21.

  • npm run build works

@longzheng
Copy link
Contributor

I have a slightly different error, but also caused by adding next to transpilePackages

In my case I was seeing

  ▲ Next.js 14.2.3

Import trace for requested module:
./node_modules/next/dist/compiled/@babel/runtime/helpers/asyncToGenerator.js
./node_modules/next/dist/client/index.js
 ⨯ ./node_modules/next/dist/compiled/@babel/runtime/helpers/asyncToGenerator.js
Module parse failed: Cannot use 'import.meta' outside a module (63:16)
|                 // still a Refresh Boundary later.
|                 // @ts-ignore importMeta is replaced in the loader
>                 import.meta.webpackHot.accept();
|                 // This field is set when the previous version of this module was a
|                 // Refresh Boundary, letting us know we need to check for invalidation or

I narrowed this down to the fact that the dev server could not be transpiled, so it only errored in npm run dev, but worked fine for npm run build.

I fixed this by conditionally transpiling only for non-dev

// next.config.js
{
   ...,
    // don't transpile in dev server as it will fail
    transpilePackages: process.env.NODE_ENV !== 'development' ? ['next'] : undefined,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants