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

webpack build includes node polyfills #6670

Closed
puckey opened this issue Jun 8, 2018 · 10 comments
Closed

webpack build includes node polyfills #6670

puckey opened this issue Jun 8, 2018 · 10 comments

Comments

@puckey
Copy link
Contributor

puckey commented Jun 8, 2018

Analyzing my radio garden webpack build, I noticed that the build includes polyfills for several node.js libraries – over 100kb minified which isn't left out of the browser build.

The reason for this is the libraries being required in loadWithHttpRequest inside Resource.js.

(For my build, I followed the webpack tutorial at https://cesiumjs.org/tutorials/cesium-and-webpack/)

@puckey puckey changed the title webpack build includes node libraries webpack build includes node polyfills Jun 8, 2018
@hpinkos
Copy link
Contributor

hpinkos commented Jun 8, 2018

Thanks @puckey

@ggetz @mramato do you have any ideas on this?

@mramato
Copy link
Contributor

mramato commented Jun 8, 2018

Related to #6671

@ggetz
Copy link
Contributor

ggetz commented Jun 8, 2018

@puckey As for the polyfills, you can exclude them from your webpack build, see https://webpack.js.org/configuration/node/.

I've write up an issue to include that in the suggested webpack config/tutorial, see CesiumGS/cesium-webpack-example#8

@puckey
Copy link
Contributor Author

puckey commented Jun 8, 2018

Setting node: false stops webpack from including the polyfills in the build, but it still wants them because they are being required in the code – causing the following build errors:

ERROR in ./lib/cesium/Source/Core/Resource.js
Module not found: Error: Can't resolve 'http' in '/client/lib/cesium/Source/Core'
 @ ./lib/cesium/Source/Core/Resource.js 1776:62-77
 @ ./lib/cesium/Source/Core/Iau2006XysData.js
 @ ./lib/cesium/Source/Core/Transforms.js
 @ ./lib/cesium/Source/Scene/SceneTransforms.js
 @ ./lib/cesium/viewer.js
 @ ./models/place.js
 @ ./models/index.js
 @ ./store/index.js
 @ ./index.js
 @ ./polyfill.js

ERROR in ./lib/cesium/Source/Core/Resource.js
Module not found: Error: Can't resolve 'https' in '/client/lib/cesium/Source/Core'
 @ ./lib/cesium/Source/Core/Resource.js 1776:43-59
 @ ./lib/cesium/Source/Core/Iau2006XysData.js
 @ ./lib/cesium/Source/Core/Transforms.js
 @ ./lib/cesium/Source/Scene/SceneTransforms.js
 @ ./lib/cesium/viewer.js
 @ ./models/place.js
 @ ./models/index.js
 @ ./store/index.js
 @ ./index.js
 @ ./polyfill.js

ERROR in ./lib/cesium/Source/Core/Resource.js
Module not found: Error: Can't resolve 'zlib' in '/client/lib/cesium/Source/Core'
 @ ./lib/cesium/Source/Core/Resource.js 1778:15-30
 @ ./lib/cesium/Source/Core/Iau2006XysData.js
 @ ./lib/cesium/Source/Core/Transforms.js
 @ ./lib/cesium/Source/Scene/SceneTransforms.js
 @ ./lib/cesium/viewer.js
 @ ./models/place.js
 @ ./models/index.js
 @ ./store/index.js
 @ ./index.js
 @ ./polyfill.js

@puckey
Copy link
Contributor Author

puckey commented Jun 8, 2018

I noticed that without setting node: false in the webpack config, requiring Cesium's Buffer.js will cause the buffer package to be included – since Buffer is a global in node.. Another reason to exclude them as @ggetz suggested!

@ggetz
Copy link
Contributor

ggetz commented Jun 8, 2018

Try node: 'empty', it'll provide an empty object so the require error won't be thrown.

@puckey
Copy link
Contributor Author

puckey commented Jun 8, 2018

That gives the following:

$ node_modules/.bin/webpack --config webpack.config.js
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration[0].node should be one of these:
   false | object { Buffer?, __dirname?, __filename?, console?, global?, process?, ... }
   -> Include polyfills or mocks for various node stuff.
   Details:
    * configuration[0].node should be false
    * configuration[0].node should be an object.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@ggetz
Copy link
Contributor

ggetz commented Jun 8, 2018

It looks like you can provide an object and specify a value per node library: https://webpack.js.org/configuration/node/#other-node-core-libraries

We should specify 'empty' for the node libraries we are referencing.

I'm going to close this issue in favor of CesiumGS/cesium-webpack-example#8. If we want to continue to troubleshoot, we should move discussion to the forum or that issue. Thanks!

@ggetz ggetz closed this as completed Jun 8, 2018
@matthias-ccri
Copy link
Contributor

Maybe cesium can leverage the new browser field in package.json?

@matthias-ccri
Copy link
Contributor

keyword: node builtins

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