0

OS: Debian 9 (stretch)

Saved Global npm install:

Building a static webapp with Next framework, npm run dev works fine in localhost:3000 with package.json:

"scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"

When building for deploy alone with npm run build this happens:

> Failed to build { Error: (client) ./pages/index.js Module not found: Error: Can't resolve 'react' in 'path/to/pages' (......) }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jp/.npm/_logs/2019-01-19T13_55_25_781Z-debug.log

I managed to build it yesterday, by reinstalling all the tech pile and giving su permission to my user (solution that's not working today again...). But when deployed with now, somehow there's a problem with the path to index.js, because the url now access can't find "./pages/index.js" and when redirected it displays the index.js in plain text instead of render the code.

SSR maybe? Trying to get my head around all this...

The same project was builded in a macOsX and deployed also with now and things worked perfectly.

So, what the hell mannn?

Installed and re-installed all the libs and main techs. Everything under the user and with suited priviledges. Recriated everything from zero in new location. Studied Next and Now's docs, as long as React's...

The closest I got to resolve the react module was with https://webpack.js.org/configuration/resolve/, but there's not a

module.exports = {
  //...
  resolve: {
    module: ['react']
  }
};

or something like that.

After all the troubleshooting, my logic is:

1 The code is fine, as it compiles and runs smoothly on other stations;

2 Maybe there's something to do with my compilation in Debian/Linux;

Can't go any further. Any help, thanks a lot.

2
  • Is React one of the project's dependencies (i.e. specified in the dependencies section of your project's package.json) or installed globally (i.e. by running npm install --global react)? Commented Jan 19, 2019 at 17:03
  • "dependencies": { "next": "^7.0.2", "react": "^16.7.0", <- npm init creates it, already changed to "latest" in troubleshooting, didn't work "react-dom": "^16.7.0" } It was installed by running "npm i -s next react react-dom", but already tried with "npm i --save --global next react react-dom"... Commented Jan 21, 2019 at 12:35

1 Answer 1

0

So... 24 days later...

The answer is in the now's doc (well hidden) witch is as follows:

"However, if you define a builds step, Now will only include the outputs that the Builders produce in the resulting deployment."

So, if I define a builder like: https://zeit.co/docs/v2/deployments/official-builders/next-js-now-next/

IT MAGICALLY WORKS!

There are a few builders ready for your preffered framework, in my case Now/Next.

SOLUTION: 2 files created:

next.config.js

module.exports = {
target: 'serverless'
}

now.json

{
"version": 2,
"builds": [{ "src": "next.config.js", "use": "@now/next" }]
} 

Check https://zeit.co/docs/v2/deployments/builds/#sources-and-outputs for more info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .