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

Next build failed: Can't resolve 'react' #154

Closed
wiktor-jurek opened this issue Mar 27, 2022 · 2 comments
Closed

Next build failed: Can't resolve 'react' #154

wiktor-jurek opened this issue Mar 27, 2022 · 2 comments

Comments

@wiktor-jurek
Copy link

Hi, whenever I npm run build my Next.js app, I get a webpack error. This may be something to do with #129 but I'm not building with any local modules/dependancies.

wiktor@MANTIS:~/Development-Linux/workspacemodels$ npm run build

> workspacemodels@0.1.0 build
> next build

info  - Loaded env from /home/wiktor/Development-Linux/workspacemodels/.env.local
warn  - SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled
Generated 9 documents in .contentlayer
info  - Checking validity of types
info  - Creating an optimized production build
Failed to compile.

./node_modules/next-contentlayer/dist/hooks/useLiveReload.js
Module not found: Can't resolve 'react' in '/home/wiktor/Development-Linux/workspacemodels/node_modules/next-contentlayer/dist/hooks'

Import trace for requested module:
./node_modules/next-contentlayer/dist/hooks/index.js
./pages/about.jsx

./node_modules/next-contentlayer/dist/hooks/useMDXComponent.js
Module not found: Can't resolve 'react' in '/home/wiktor/Development-Linux/workspacemodels/node_modules/next-contentlayer/dist/hooks'

Import trace for requested module:
./node_modules/next-contentlayer/dist/hooks/index.js
./pages/about.jsx

./node_modules/next-contentlayer/dist/hooks/useMDXComponent.js
Module not found: Can't resolve 'react/jsx-runtime.js' in '/home/wiktor/Development-Linux/workspacemodels/node_modules/next-contentlayer/dist/hooks'

Import trace for requested module:
./node_modules/next-contentlayer/dist/hooks/index.js
./pages/about.jsx

./node_modules/next-contentlayer/dist/hooks/useMDXComponent.js
Module not found: Can't resolve 'react-dom' in '/home/wiktor/Development-Linux/workspacemodels/node_modules/next-contentlayer/dist/hooks'

Import trace for requested module:
./node_modules/next-contentlayer/dist/hooks/index.js
./pages/about.jsx

./node_modules/next-themes/dist/index.modern.js
Module not found: Can't resolve 'react' in '/home/wiktor/Development-Linux/workspacemodels/node_modules/next-themes/dist'

Import trace for requested module:
./pages/_app.js


> Build failed because of webpack errors

Here are my packages:

    "@mdx-js/loader": "^2.0.0",
    "@next/mdx": "^12.1.0",
    "classnames": "^2.3.1",
    "contentlayer": "^0.1.2",
    "date-fns": "^2.28.0",
    "next": "12.1.0",
    "next-contentlayer": "^0.1.2",
    "next-themes": "^0.1.1",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "swr": "^1.2.2"

And here's a repo link.

Any help very much appreciated!

@schickling
Copy link
Collaborator

Hi @wiktor-jurek - thanks for opening this issue and providing a link to your repo. I've taken a brief look and it seems the problem is related to you patching the config.resolve.alias Webpack config - I assume for the sake of using Preact? However, I don't see any Preact deps installed.

Simply commenting out these lines in your next.config.js seemed to make the next build work for me.

image

In case you actually intend to use Preact, please refer to this issue #62.

Closing this issue for now but happy to re-open in case I misunderstood the situation.

@wiktor-jurek
Copy link
Author

Thanks so much. That's it. That's what I get for blindly coping .next configs... 🙄

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

2 participants