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

Cannot find module 'next/babel' with Yarn 2 and Next.js 10.0.2 #19334

Closed
fmal opened this issue Nov 19, 2020 · 14 comments · Fixed by #19518 or babel/babel#12439
Closed

Cannot find module 'next/babel' with Yarn 2 and Next.js 10.0.2 #19334

fmal opened this issue Nov 19, 2020 · 14 comments · Fixed by #19518 or babel/babel#12439
Milestone

Comments

@fmal
Copy link

fmal commented Nov 19, 2020

Bug report

Describe the bug

When using Yarn 2.3.3 with Next.js 10.0.2 and custom .babelrc file that extends default preset next/babel (according to https://nextjs.org/docs/advanced-features/customizing-babel-config), yarn run dev results in Cannot find module 'next/babel' error.
Prior to 10.0.2 this used to work without error.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. yarn create next-app my-app
  2. cd my-app
  3. yarn set version berry && yarn set version latest && yarn install
  4. create .babelrc file with the following contents:
{
  "presets": ["next/babel"]
}
  1. yarn run dev
  2. see error

Expected behavior

no errors and the dev environment starts fine.
the following work as expected:

  • Next.js 10.0.1 and Yarn 2.3.3

Screenshots

Screenshot 2020-11-19 at 23 54 44

System information

  • OS: macOS
  • Version of Next.js: 10.0.2
  • Version of Node.js: 14.13.0

Additional context

N/A

@fmal fmal added the bug Issue was opened via the bug report template. label Nov 19, 2020
@Timer Timer added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 23, 2020
@Timer Timer added this to the iteration 14 milestone Nov 23, 2020
SagnikPradhan added a commit to d-zone-org/d-zone that referenced this issue Nov 25, 2020
Latest version of next.js doesn't work under pnp.
Look here vercel/next.js#19334
Fixed by downgrading next.

Also added pixi.js as an alias to pixi.js-legacy
As pixi-viewport was complaining under pnp
@meotimdihia
Copy link

meotimdihia commented Nov 25, 2020

same here on Ubuntu 20 for Windows. Nodejs 12.
WindowsTerminal_2020-11-25_18-52-57

@c0
Copy link

c0 commented Dec 12, 2020

One workaround is to turn off yarn 2's PNP:

yarnrc.yml

nodeLinker: "node-modules"

Credit to @SagnikPradhan in his PR above.

@jensmeindertsma
Copy link

Is there anything I can do to help this get fixed as soon as possible?

@andrewmclagan
Copy link
Contributor

andrewmclagan commented Dec 17, 2020

@jensmeindertsma write a PR.

seeing this on 10.0.4-canary.7. One solution is to simply not have the babel config file (remove it) if you have the default.

@jensmeindertsma
Copy link

One solution is to simply not have the babel config file (remove it) if you have the default.

This is true, but I need one for ESLint with @babel/parser

@paperdave
Copy link

idk why no one has mentioned it but you can change "next/babel" with require.resolve("next/babel") and it works on yarn 2 with pnp on the latest release of next as of writing which seems to be 10.0.3.

you'll need a babel.config.js not a .babelc though. heres an example

module.exports = {
  presets: [
    require.resolve('next/babel')
  ]
};

then yarn dev and it should be working. i tested this using a custom server but it shouldn't matter

however this should still be fixed in the actual codebase. i wonder what is causing it since resolve and require.resolve should resolve the package just fine (the package should work now according to yarn docs, and we're literally using require.resolve).

@fmal
Copy link
Author

fmal commented Dec 20, 2020

@davecaruso great hint, also if you're working in a monorepo context, you could have babel.config.js with babelrcRoots specified in repo root and use .babelrc.js with require.resolve("next/babel") as you suggested instead of .babelrc inside of a package

@merceyz
Copy link
Contributor

merceyz commented Jan 9, 2021

Fixed in #20586 (v10.0.5-canary.4)

@fmal
Copy link
Author

fmal commented Jan 10, 2021

@merceyz thank you!

@fmal fmal closed this as completed Jan 10, 2021
kodiakhq bot pushed a commit that referenced this issue Jan 11, 2021
**What's the problem this PR addresses?**

- ~~#18768 started to ncc babel and thus it's version of resolve which breaks PnP support~~
Babel replaced `resolve` with the builtin `require.resolve` and a polyfill for older node versions in babel/babel#12439 which was upgraded in #20586
- `next` unnecessarily bundles the `resolve` package when `require.resolve` is builtin and can do the same job

**How did you fix it?**

- ~~Avoid running `resolve` through ncc~~
Added a test for #19334 (closes #19334)
- Replace `resolve` with `require.resolve`
@arifali123
Copy link

idk why no one has mentioned it but you can change "next/babel" with require.resolve("next/babel") and it works on yarn 2 with pnp on the latest release of next as of writing which seems to be 10.0.3.

you'll need a babel.config.js not a .babelc though. heres an example

module.exports = {
  presets: [
    require.resolve('next/babel')
  ]
};

then yarn dev and it should be working. i tested this using a custom server but it shouldn't matter

however this should still be fixed in the actual codebase. i wonder what is causing it since resolve and require.resolve should resolve the package just fine (the package should work now according to yarn docs, and we're literally using require.resolve).

This worked perfectly thank you very much

@jplew
Copy link

jplew commented Jul 1, 2021

I was getting this error because I was trying to edit _app.js in a Typescript project. I renamed it to _app.tsx and the editor warning disappeared. 🤦‍♂️

@igdev116
Copy link

igdev116 commented Sep 4, 2021

Because you weren't opening the project folder directly. It appears to be related to how ESLint needs to be configured for workspaces. Just create a folder name .vscode/settings.json on your working directory and add those code:

{
  "eslint.workingDirectories": [
      "./folder_name_1",
      "./folder_name_2",
  ]
}

And the warning will disappear! Hope it works for you 😄

Source: https://stackoverflow.com/questions/68163385/parsing-error-cannot-find-module-next-babel

@GGAlanSmithee
Copy link

@igdev116 thank you very much for this! 👍

roc added a commit to nhsx/standards-registry that referenced this issue Nov 22, 2021
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet