jaredpalmer / razzle

✨ Create server-rendered universal JavaScript applications with no configuration
https://razzlejs.org
MIT License
11.1k stars 866 forks source link

Node.js 8.0.0+ compatibility issue #287

Closed kireerik closed 7 years ago

kireerik commented 7 years ago

I have installed Node.js 8.0.0 under Windows 10 and I am getting the following errors when I am using the razzle start command:

\node_modules\razzle\config\create-config.js:60
        process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
                             ^

TypeError: Cannot read property 'split' of undefined
    at module.exports (\node_modules\razzle\config\create-config.js:60:30)
    at Object.<anonymous> (\node_modules\razzle\scripts\start.js:35:20)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
\node_modules\execa\index.js:277
                throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr));
                ^

Error: null
    at Function.module.exports.sync (\node_modules\execa\index.js:277:26)
    at Object.<anonymous> (\node_modules\razzle\bin\razzle.js:12:9)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
error Command failed with exit code 1.

I am getting a similar error for razzle build as well.

With Node.js 7.10.0 it worked and it still works if I install it back.

jaredpalmer commented 7 years ago

This line comes directly from https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/config/webpack.config.dev.js#L89

Can you try the latest create-react-app to see if you have the same issue?

kireerik commented 7 years ago

I see.

Sure, now I have tested it and create-react-app works with both versions of Node.js.

kireerik commented 7 years ago

Also I have used create-react-app as a global module, but I always use razzle as a local module.

jaredpalmer commented 7 years ago

I don't have a way to test this out unfortunately. I don't own a Windows PC. 😢

kireerik commented 7 years ago

I see. So this issue doesn't occurs on your Mac?

It is possible to use Windows in a virtual box.

Running the following code using the Node.js console

console.log(process.env.NODE_PATH)

I am getting the following output:

undefined
undefined

Is this the expected behavior?

Also accourding to Razzle's source code it is not really possible that the process.env.NODE_PATH is undefined, because in this case it is set to ''.

jaredpalmer commented 7 years ago

hmm.. i'm just not seeing this.

screenshot 2017-06-06 18 37 51
jaredpalmer commented 7 years ago

Just tested, that in create-react-app process.env.NODE_PATH is undefined.

kireerik commented 7 years ago

So you have the same issue with create-react-app, but not with Razzle?

jaredpalmer commented 7 years ago

Nope. They have identical behavior because the code that handles NODE_PATH is copied directly CRA

https://github.com/facebookincubator/create-react-app/blob/d24311ea79704361c8a5fa7fedb04013de6860e8/packages/react-scripts/config/env.js#L59

https://github.com/jaredpalmer/razzle/blob/master/packages/razzle/config/env.js#L46

kireerik commented 7 years ago

I see.

In env.js it is definitely ''.

Interestingly if I console log it in create-config.js like this:

console.log(process.env.NODE_PATH)

Than I get this result:

$ razzle start
 WAIT  Compiling...

undefined
undefined
 DONE  Compiled successfully
...

So the server starts successfully.

Do you think I should report this issue at @facebookincubator's create-react-app as well?

jaredpalmer commented 7 years ago

Yes

kireerik commented 7 years ago

Well, create-react-app now works for me with Node.js 8.

gaearon commented 7 years ago

Maybe code using NODE_PATH runs earlier than its initialization gets a chance to run? We used to have an issue like this.

jaredpalmer commented 7 years ago

@kireerik What happens if you set NODE_PATH in your npm scripts?

{
  ...
  "scripts": {
      "start": "NODE_PATH=src razzle start",
      "test": "NODE_PATH=src razzle test",
       ...
   }
}
kireerik commented 7 years ago

It works that way if I do it correctly like this: cross-env NODE_PATH=src razzle start

jaredpalmer commented 7 years ago

@gaearon does CRA use cross-env under the hood?

kireerik commented 7 years ago

set NODE_PATH=src && razzle start works as well. (and I use src exacty)

gaearon commented 7 years ago

@jaredpalmer No (it doesn't launch processes for build/start unless I misunderstand something). We assing NODE_ENV ourselves depending on script, and ignore what the user set.

sumankundu220 commented 7 years ago

replace NODE_PATH with PATH like process.env.PATH

paOol commented 7 years ago

same issues here

npm start

> my-razzle-app@0.1.0 start C:\web\frab
> razzle start

 WAIT  Compiling...

C:\web\frab\node_modules\razzle\config\createConfig.js:60
        process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
                             ^

TypeError: Cannot read property 'split' of undefined
    at module.exports (C:\web\frab\node_modules\razzle\config\createConfig.js:60:30)
    at Object.<anonymous> (C:\web\frab\node_modules\razzle\scripts\start.js:34:20)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-razzle-app@0.1.0 start: `razzle start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-razzle-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
stoikerty commented 7 years ago

Looks like it's a race-condition, created a PR with the fix.

kireerik commented 7 years ago

Thank you @stoikerty! I couldn't spot the root cause of this issue. It was so strange to me.

jaredpalmer commented 7 years ago

Wooo!!!

kireerik commented 7 years ago

Sorry, I thought this issue is resolved by now. At least it is working for me with the latest pre-release. Am I wrong with that?

jaredpalmer commented 7 years ago

Pressed the wrong button. ;)

stereobooster commented 6 years ago

Have the same issue. Only set NODE_PATH=src && razzle start worked for me