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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodeRequire is not a function #7669

Closed
bkuster opened this issue Mar 22, 2019 · 8 comments · Fixed by #10399
Closed

nodeRequire is not a function #7669

bkuster opened this issue Mar 22, 2019 · 8 comments · Fixed by #10399

Comments

@bkuster
Copy link
Contributor

bkuster commented Mar 22, 2019

The Issue:

After updating one of my server components from npm cesium 1.50 to 1.55, I can no longer request resources do to the following error: nodeRequire is not a function.

What has changed:

https://github.com/AnalyticalGraphicsInc/cesium/blob/ead9f36a9b155a1d2dada9f8724b531d09195c7a/Source/Core/Resource.js#L1913-L1918

What causes the Issue

This does not play nicely with webpack.

Tried work arounds:

  • Defining global.require = require within my code -> webpack cant find url.
  • Ignoring cesium with noParse -> missing define.
@bkuster
Copy link
Contributor Author

bkuster commented Mar 22, 2019

So, I found this solution: within my entry point I added this line:

global.require = __non_webpack_require__;

@mramato do you see another, potentially more elegant, solution? Otherwise, feel free to close this.

@bkuster
Copy link
Contributor Author

bkuster commented Mar 22, 2019

Little update: While debugging my script, I came across the same error again, this time not webpack related. I had to add this to my source file, to get it to work:

global.require = process.env.NODE_ENV === 'production' ? __non_webpack_require__ : require;

@bkuster
Copy link
Contributor Author

bkuster commented Mar 28, 2019

So, I added the following little repo to outline the issue better and maybe give you a better understanding of where the issue lies.
https://github.com/bkuster/minimal-cesium-test

@mramato
Copy link
Contributor

mramato commented Mar 28, 2019

Thanks for the detailed write up @bkuster and sorry for the slow reply here. Unfortunately webpack's fragility has led to breakage like this in the past but it should hopefully be an easy fix, we may actually be able to just revert the change that caused this problem to begin with, but I'll know more once I dig into it.

We'll definitely try and get this fixed before the next release.

@mramato
Copy link
Contributor

mramato commented Mar 29, 2019

@bkuster Sorry if I'm missing something obvious but just wanted to confirm your exact use case. It looks like you are writing a Node.js app but using webpack to build it? This isn't a browser application but a Node one?

@bkuster
Copy link
Contributor Author

bkuster commented Mar 29, 2019

@mramato, yes that is the use case. I know it's an atypical approach, but we mangle our server side code sometimes. Note, that in the repo I provided, the error remains the same with or without webpack (but using the amd-loader).

@mramato
Copy link
Contributor

mramato commented Apr 1, 2019

Thanks. Building/minifying Node.js code is actually something I need to explore myself at some point, so I understand the use case.

I need to think through all of the implications here so we don't break one of the other combinations by fixing this use case. Unfortunately that means a fix won't make it into today's release, but I'm hopeful it will with the next one. Your repository example will be a huge help.

@bkuster
Copy link
Contributor Author

bkuster commented Apr 1, 2019

@mramato thanks for the update. I did not expect a quick fix tbh. and have found a workaround which works fine for now (but is very webpack specific).

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

Successfully merging a pull request may close this issue.

3 participants