I tried to build my next.js app on both my Linux and Windows machines. But both of them fails with the following error:
react not found. Please install react using 'npm install react'
react-dom not found. Please install react-dom using 'npm install react-dom'
(node:3120) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
Any idea why?
Have you installed them?
If yes, could you provide repo to reproduce the issue?
Sure. I just uploaded the codeto a git repo: https://github.com/THPubs/nextBlogTest
This works pretty well for me.
Had to do this:
diff --git a/pages/index.js b/pages/index.js
index 0544458..2806d87 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -43,9 +43,9 @@ class HomePage extends Component {
render(){
return (
<div>
- <HEAD>
+ <Head>
<meta name="google-site-verification" content="-54zHeU7cqpHWDRkfEXJCWUjlZSCEtS-te8Y7GvQzrU" />
- </HEAD>
+ </Head>
<ul>
<li></li>
<li><Link href='/blog?id=second' as='/second'><a>My second blog post</a></Link></li>
May be you need to do npm install
Hi @arunoda I already ran npm install
several times. :cry:
Just got it fixed. Removed the node_modules
folder and re-ran yarn install!
Hi, I have the same issue:
react not found. Please install react using 'npm install react'
react-dom not found. Please install react-dom using 'npm install react-dom'
{ Error: Cannot find module 'react/dist/react.min.js'
at Function.Module._resolveFilename (module.js:485:15)
at Function.resolve (internal/module.js:18:19)
at _callee2$ (/usr/local/lib/node_modules/next/dist/server/build/webpack.js:517:34)
at tryCatch (/usr/local/lib/node_modules/next/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (/usr/local/lib/node_modules/next/node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/next/node_modules/regenerator-runtime/runtime.js:117:21)
at step (/usr/local/lib/node_modules/next/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /usr/local/lib/node_modules/next/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at Promise (<anonymous>)
at F (/usr/local/lib/node_modules/next/node_modules/core-js/library/modules/_export.js:35:28) code: 'MODULE_NOT_FOUND' }
Tried yarn install and npm install after removing the node_modules folder and I still get the same error. I also tried to change the versions of the dependencies as well as the node version...still the same issue. I clone the next.js repo, install the dependencies and tried to build some examples...still the same issue :s
update: I get this error only when I type next build
but if I run this command from the package.json everything works fine.
I have this issue too, npm run build
works fine and it all works perfectly, but next build
throws:
The module 'react' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install --save react'
The module 'react-dom' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install --save react-dom'
Error: Cannot find module 'react' `
it seems that it has something todo with the next
path handling...you can only run next
commands from `package.json, which is inside the project folder root like this:
"build": "next build",
and run: npm run build
instead of running it directly from the command line next build
which will throw the error...
tested on npm v4.1.2 and v5.5.1
one can also use ./node_modules/.bin/next build
for replacement
Alternatively, you can run npx next build
(requires [email protected] or higher).
Explanation: Running next build
uses the global installation of next
and I think that it also looks for a global installation of react
and react-dom
. Running npx next build
uses the local installation of next
, react
and react-dom
.
Perhaps just speculation, but I ran into this a few times when trying to start a project called "next-test" -- running npm init
without the force argument let me know there were some problems installing next
because it matched the name of the project (at least partially). I renamed the project and it worked.
Something to try if you hit this wall a couple times, like I did.
Ran into this during Wes Bos' Advanced React course--confirming that running next build
resulted in the error while running an npm task that pointed to next build
executed as expected.
Most helpful comment
update: I get this error only when I type
next build
but if I run this command from the package.json everything works fine.