Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

"self" is not defined error on server side generated entry file #276

Closed
annelin07 opened this issue Mar 17, 2019 · 4 comments
Closed

"self" is not defined error on server side generated entry file #276

annelin07 opened this issue Mar 17, 2019 · 4 comments

Comments

@annelin07
Copy link

annelin07 commented Mar 17, 2019

馃挰 Questions and Help

Loadable Components project is young, but please before asking your question:

  • Read carefully the README of the project
    YES
  • Search if your answer has already been answered in old issues
    YES
    After you can submit your question and we will be happy to help you!

Hello,
Thanks for the SSR example, I followed the example, the differences from the SSR example vs mine are:

  1. instead of using webpack-dev-middle for express, I'm using webpack-dev-server
  2. instead of starting webpack-dev-server from Nodejs API, I'm running webpack-dev-server from command line for hapi, and added the writeToDisk option to devServer.

Now on server side when it calls

  const nodeExtractor = new ChunkExtractor({ statsFile: webStats });
  const { default: App } = nodeExtractor.requireEntrypoint(); 

which tries to require server side entry file - dist/js/node/main.bundle.dev.js, I'm getting error on window is not defined:

"error":"self is not defined","errorStack":"ReferenceError: self is not defined\n    at Object.<anonymous> (webpack:///(webpack)-dev-server/client:217:1)\n    at Object.../../node_modules/webpack-dev-server/client/index.js?http://localhost:2992

The error seems to come from webpack-dev-server referencing self: https://github.com/webpack/webpack-dev-server/blob/2f7f05276e10a2ce408e0903982b8bbe07699182/client-src/default/index.js#L46

Tried as suggest here - markdalgleish/static-site-generator-webpack-plugin#130 with

output: {
  // ...
  globalObject: "this"
}

or

output: {
  // ...
  globalObject: `typeof self !== 'undefined' ? self : this`
}

even disabling HMR, none works.

Any idea how to resolve this? Appreciate your help!

Thanks

@annelin07 annelin07 changed the title window is not defined error on server side generated entry file "self" is not defined error on server side generated entry file Mar 18, 2019
@luanlucho
Copy link

How did you solve it?

@rxkevin
Copy link

rxkevin commented Apr 21, 2021

This did the trick for me:

output: {
  // ...
  globalObject: `typeof self !== 'undefined' ? self : this`
}

@bennycode
Copy link

What's the magic behind globalObject?

I am receiving the error ReferenceError [Error]: self is not defined and webpack's stacktrace points me to the line of var chunkLoadingGlobal = self["webpackChunk_wireapp_cryptobox"]. When I am using globalObject: "this", then webpack creates var chunkLoadingGlobal = this["webpackChunk_wireapp_cryptobox"] but throws TypeError [Error]: Cannot read property 'webpackChunk_wireapp_cryptobox' of undefined. 馃槬

@ajayjaggi97
Copy link

Were you able to solve this?? I am getting the same error but my use case is different..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants