Cesium and webpack-5

Hi,

I am trying to do a webpack of cesium into a widget (CesiumWidget for Jupyter python environment), but I am struggling at getting this working. I am by no means an expert of javascript, but has tried to follow a few tutorials and documentations available. But they seems to be not completely in sync and not sure what is changed and not.

The tutorial at the cesium webpage, is that up to date?

It differs a bit from the example at:

I tried to update the webpack example above for webpack 5 (I think I need to use this version for jupyterlab), PR available at Updates for using webpack 5. Please review by petrushy · Pull Request #25 · CesiumGS/cesium-webpack-example · GitHub
The standalone example seems to work with that PR, but the integration into other application is failing.

Somehow I think that the CopyWebpackPlugin files are not included in the final output. They are visible in the dist directory but somehow not included in the webpack or are they served directly from the dist directory?

Quite confused :slight_smile:

Hi. I think I am facing the same challenge, trying to integrate Cesium with webpack using the tutorial on the Cesium website.
After doing every step according to the tutorial, when I finally run the “npm start” command, I face the following error:

> 0 info it worked if it ends with ok
> 1 verbose cli [
> 1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
> 1 verbose cli   'C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
> 1 verbose cli   'start'
> 1 verbose cli ]
> 2 info using npm@6.14.9
> 3 info using node@v12.18.3
> 4 verbose run-script [ 'prestart', 'start', 'poststart' ]
> 5 info lifecycle example02@1.0.0~prestart: example02@1.0.0
> 6 info lifecycle example02@1.0.0~start: example02@1.0.0
> 7 verbose lifecycle example02@1.0.0~start: unsafe-perm in lifecycle true
> 8 verbose lifecycle example02@1.0.0~start: PATH: C:\Users\user\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\user\Desktop\internship\neo\cesium-webpack-app\example02\node_modules\.bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Python38\Scripts\;C:\Program Files\Python38\;C:\Windows\System32;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\user\Anaconda3\Scripts;C:\Users\user\Anaconda3;"C:\Users\user\Anaconda3\Library\bin;";"C:\Users\user\Anaconda3\Library\user\bin;";"C:\Users\user\Anaconda3\Library\mingw-w64\bin;";C:\Program Files (x86)\Yarn\bin\;C:\Program Files\MongoDB\Server\4.4\bin;C:\Program Files\MongoDB\Tools\100\bin;C:\Program Files\PostgreSQL\9.6\bin\psql.exe;C:\Program Files\PostgreSQL\9.6\bin;C:\Program Files\PostgreSQL\9.6\lib;C:\Program Files\PostgreSQL\13\bin;C:\Program Files\PostgreSQL\13\lib;C:\Program Files (x86)\Calibre2\;C:\ProgramData\Anaconda3\Library\bin\graphviz;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\GDAL;C:\Program Files\GDAL\gdal-data;C:\ProgramData\Anaconda3\Library\bin\graphviz;C:\ProgramData\Anaconda3\Library\bin\graphviz;C:\ProgramData\Anaconda3\Library\bin\graphviz;C:\ProgramData\Anaconda3\Library\bin\graphviz;C:\Users\user\AppData\Local\Microsoft\WindowsApps;C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user\AppData\Roaming\npm;C:\Users\user\AppData\Local\Yarn\bin
> 9 verbose lifecycle example02@1.0.0~start: CWD: C:\Users\user\Desktop\internship\neo\cesium-webpack-app\example02
> 10 silly lifecycle example02@1.0.0~start: Args: [ '/d /s /c', 'webpack serve' ]
> 11 silly lifecycle example02@1.0.0~start: Returned: code: 2  signal: null
> 12 info lifecycle example02@1.0.0~start: Failed to exec start script
> 13 verbose stack Error: example02@1.0.0 start: `webpack serve`
> 13 verbose stack Exit status 2
> 13 verbose stack     at EventEmitter.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
> 13 verbose stack     at EventEmitter.emit (events.js:315:20)
> 13 verbose stack     at ChildProcess.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
> 13 verbose stack     at ChildProcess.emit (events.js:315:20)
> 13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
> 13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
> 14 verbose pkgid example02@1.0.0
> 15 verbose cwd C:\Users\user\Desktop\internship\neo\cesium-webpack-app\example02
> 16 verbose Windows_NT 10.0.18363
> 17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
> 18 verbose node v12.18.3
> 19 verbose npm  v6.14.9
> 20 error code ELIFECYCLE
> 21 error errno 2
> 22 error example02@1.0.0 start: `webpack serve`
> 22 error Exit status 2
> 23 error Failed at the example02@1.0.0 start script.
> 23 error This is probably not a problem with npm. There is likely additional logging output above.
> 24 verbose exit [ 2, true ]

I’ve tried several solutions that I found online, but nothing worked. Here is my webpack.config.js file:
‘’’

> const path = require('path');
> 
> const CopywebpackPlugin = require('copy-webpack-plugin');
> 
> // The path to the CesiumJS source code
> const cesiumSource = 'node_modules/cesium/Source';
> const cesiumWorkers = '../Build/Cesium/Workers';
> 
> const webpack = require('webpack');
> const HtmlWebpackPlugin = require('html-webpack-plugin');
> 
> module.exports = {
> 
>     mode: 'development',
>     context: __dirname,
>     entry: {
>         app: './src/index.js'
>     },
>     resolve: {
>         alias: {
>             // CesiumJS module name
>             cesium: path.resolve(__dirname, cesiumSource)
>         }
>     },
>     output: {
>         filename: '[name].js',
>         path: path.resolve(__dirname, 'dist'),
> 
>         // Needed to compile multiline strings in Cesium
>         sourcePrefix: ''
>     },
>     amd: {
>         // Enable webpack-friendly use of require in Cesium
>         toUrlUndefined: true
>     },
>     node: {
>         // Resolve node module use of fs
>         fs: 'empty'
>     },
>     module: {
>         rules: [{
>             test: /\.css$/,
>             use: [ 'style-loader', 'css-loader' ]
>         }, {
>             test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
>             use: [ 'url-loader' ]
>         }]
>     },
>     plugins: [
>         new HtmlWebpackPlugin({
>             template: 'src/index.html'
>         }),
>         // Copy Cesium Assets, Widgets, and Workers to a static directory
>         new CopywebpackPlugin({ 
>             patterns: [
>                 { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
>                 { from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
>                 { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }
>             ]
>         }),
>         new webpack.DefinePlugin({
>             // Define relative base path in cesium for loading assets
>             CESIUM_BASE_URL: JSON.stringify('')
>         })
>     ],
> 
>     // development server options
>     devServer: {
>         contentBase: path.join(__dirname, "dist")
>     }
> };

I am thinking it might be a problem with the configuration in webpack-dev.
Does anyone have an idea about this?

Thank you in advance

Is the tutorial still up to date?

It is not - i’m also hitting issues with Cesium + Webpack 5.
I hope they update the docs soon for Webpack 5

Anybody got workers in 5 setup and can share? We have trouble using workers and packages that use cesium at the same time.
Dependencies using cesium cause an error
Uncaught (in promise) Error: Cannot find module ‘/Build/CesiumUnminified/index.cjs’

Also: Is CESIUM_BASE_URL even still involved in worker setup and do they still need to be copied around? Workers are now: not inlined in Build/Cesium but not Build/CesiumUnminified?