node.jsnext.jsnode-modulesyarnpkg

Creating a new next.js project with yarn results in error: "Cannot find module"


I created a next.js project using yarn. The commands used are below.

I get an error that the module does not exist in the editor.
The error is resolved after re-installing with npm. But with yarn, I get an error.

I tried to re-create the project and still got an error if it was yarn. I also get an error with yarn in all editors.

Commands used

yarn create next-app
yarn install
yarn cache clean
yarn build

enter image description here


Solution

  • The reason is that dependencies by default are no longer installed under node_modules, if you're looking for that behavior, add to .yarnrc.yml the following line: nodeLinker: node-modules