Skip to content

react-scripts-build => 'navigator is not defined' #1875

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

Closed
ztotta opened this issue Mar 21, 2017 · 8 comments
Closed

react-scripts-build => 'navigator is not defined' #1875

ztotta opened this issue Mar 21, 2017 · 8 comments

Comments

@ztotta
Copy link

ztotta commented Mar 21, 2017

Attempting to build & deploy to gh-pages, but it's failing at 'react-scripts-build', throwing 'Module build failed: ReferenceError: navigator is not defined'. It appears to be coming from App.css, but I can't find what 'navigator' is referring to in the first place. Do you know what 'navigator' refers to and what could be causing this?

Here's the commit of the project at this point: ztotta/zach_totta@e7ec3e6

And here's the log:

react-scripts build

Creating an optimized production build...
Failed to compile.

**Module build failed: ReferenceError: navigator is not defined**
    at Object.module.exports.e.__esModule.default (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35005:25079)
    at t (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:122)
    at Object.<anonymous> (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35005:29200)
    at t (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:122)
    at Object.<anonymous> (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:513)
    at t (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:122)
    at /Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:210
    at Object.<anonymous> (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35004:215)
    at __webpack_require__ (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:21:30)
    at Object.<anonymous> (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:35014:19)
    at __webpack_require__ (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:21:30)
    at Object.<anonymous> (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:37709:32)
    at __webpack_require__ (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:21:30)
    at Object.module.exports.Object.defineProperty.value (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:37077:23)
    at __webpack_require__ (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:21:30)
    at Object.module.exports.Object.defineProperty.value (/Users/mac/programming-projects/Portfolio/node_modules/css-loader/index.js?importLoaders=1!/Users/mac/programming-projects/Portfolio/node_modules/postcss-loader/index.js!/Users/mac/programming-projects/Portfolio/src/App.css:37834:13)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script 'react-scripts build'.```
@darrenscerri
Copy link
Contributor

Remove the line https://github.com/ztotta/Portfolio/blob/e7ec3e6abc19bb9f6761aa755287b4db0d8aa195/src/App.css#L162 (App.css:162)

There is an empty URL which is trying to be resolved. I agree though, the error is quite cryptic.

@ztotta
Copy link
Author

ztotta commented Mar 21, 2017

Thank you!!!

@ztotta ztotta closed this as completed Mar 21, 2017
@gaearon
Copy link
Contributor

gaearon commented Mar 21, 2017

Wow, that error is super confusing.
Let's reopen until we file a bug in style-loader (or whatever is generating this).

@gaearon
Copy link
Contributor

gaearon commented Mar 21, 2017

Tagging as up for grabs. The follow up item here is to create a minimal reproducing case with just Webpack (no CRA) and file a bug in the appropriate project (it's likely either style-loader or css-loader).

@darrenscerri
Copy link
Contributor

darrenscerri commented Mar 22, 2017

Ok finally found out what the problem is. Webpack is trying to load '' from ./src/App.css, and and resolves it to ./src/index.js. Webpack, for some reason, then proceeds to execute all the code found in this file and its dependencies and finally crashes due to being in strict mode when trying to load react-responsive-sidebar and navigator is not defined (https://github.com/gregchamberlain/react-responsive-sidebar/blob/master/src/Sidebar.js#L93).

It's quite weird that Webpack actually executes the code inside the files. You can also see console.log output from the client code itself while the bundle is being built!

If you change ./src/index.js to this:

import './App.css';
console.log('========= Oopsie! !========');
require('react-responsive-sidebar');

screen shot 2017-03-22 at 02 58 40

This obscure behaviour when importing '' has since been fixed here webpack/webpack#2006.

@gaearon
Copy link
Contributor

gaearon commented Mar 22, 2017

So what is the next step here? Is this supposed to be fixed in Webpack? Should we file another issue?

@darrenscerri
Copy link
Contributor

Thought this issue was fixed for Webpack ^2.1.0 but apparently this is only fixed for specific require calls. css-loader and extract-text-webpack-plugin both seem to have related issues. Filed issues here:

webpack/webpack#4541
webpack-contrib/css-loader#462
webpack-contrib/extract-text-webpack-plugin#465

This is a repo that reproduces these issues:
https://github.com/darrenscerri/webpack-extract-text-plugin-empty-require-error

@gaearon
Copy link
Contributor

gaearon commented Mar 22, 2017

Cool, I'll close our issue then. Thanks for following up.

@gaearon gaearon closed this as completed Mar 22, 2017
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants