gajus / isomorphic-webpack

Abstracts universal consumption of application code base using webpack.
Other
291 stars 17 forks source link

`self is not defined` on demo #32

Closed jonkwheeler closed 7 years ago

jonkwheeler commented 7 years ago

Hey guys, all I did was follow the README and immediately hit an error.

These commands

git clone git@github.com:gajus/isomorphic-webpack-demo.git
cd ./isomorphic-webpack-demo
npm install
export DEBUG=express:application,isomorphic-webpack
npm start

yields this on page load of http://127.0.0.1:8000/

ReferenceError: self is not defined
    at isomorphic-webpack:195:30
    at isomorphic-webpack:190:47
    at module.exports (isomorphic-webpack:212:68)
    at Object.module.exports (isomorphic-webpack:440:36)
    at __webpack_require__ (isomorphic-webpack:20:30)
    at Object.<anonymous> (isomorphic-webpack:88:14)
    at __webpack_require__ (isomorphic-webpack:20:30)
    at evalBundleCode (/isomorphic-webpack-demo/node_modules/isomorphic-webpack/dist/factories/createIsomorphicWebpack.js:141:12)
    at /isomorphic-webpack-demo/src/bin/server.js:62:30
    at Layer.handle [as handle_request] (/isomorphic-webpack-demo/node_modules/router/lib/layer.js:93:5)
gajus commented 7 years ago

Sounds like self is something thats in your code base.

I am guessing that you have code that references self. Try to replace it with window.self.

jonkwheeler commented 7 years ago

Not sure what to say. I haven't changed any code. I cloned the repo and ran the commands noted in the README to get the demo running. Searching self on the repo locally only returned a result in the package-lock.json file.

screenshot 2017-08-21 12 54 11
laggingreflex commented 7 years ago

related: #20?

gajus commented 7 years ago

Ah, yes, it appears to be. Sorry, I am overloaded the past 6 months. Closing as duplicate.

https://github.com/gajus/isomorphic-webpack/issues/20

jonkwheeler commented 7 years ago

Ah. As someone else mentioned in that thread, reverting back to style-loader@0.13.1 worked for me. Does the demo need to be updated?

gajus commented 7 years ago

https://github.com/webpack-contrib/style-loader/issues/199 this issue mentions that it has been fixed. Maybe the solution is to upgrade, rather than downgrade.

An alternative fix would be to simply add self and other common used vars to global scope. https://github.com/gajus/isomorphic-webpack/blob/50e8896e79023314adcb1471a48319bd842ee55b/src/utilities/evalCodeInBrowser.js#L24-L35

jonkwheeler commented 7 years ago

Just wanted to confirm that upgrading style-loader to 0.18.2 caused the app to fail.

yarn start v0.27.5
warning ../../package.json: No license field
$ babel-node ./src/bin/server.js
keywords if/then/else require v5 option

ERROR in ./src/app/style.css
Module build failed: Validation Error

Style Loader Invalid Options

options.sourceMap should be boolean

 @ ./src/app/index.js 15:13-35
 @ multi ./src/app
webpack: Failed to compile.

Someone mentions not supporting SSR.

I'll see about adding your alternative fix.