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

Latest CesiumJS (v1.98.1) doesn't work on Angular v14 as a module #10854

Closed
spiderdab opened this issue Oct 13, 2022 · 3 comments
Closed

Latest CesiumJS (v1.98.1) doesn't work on Angular v14 as a module #10854

spiderdab opened this issue Oct 13, 2022 · 3 comments

Comments

@spiderdab
Copy link

spiderdab commented Oct 13, 2022

Operating System: Pop! OS 22.04
Angular/CLI version: 14.0.1
@angular-builders/custom-webpack version: 14.0.1
Cesium version: 1.98.1

installed CesiumJS with:
npm install --save-dev cesium

followed instruction taken here:
#8673

and changed angular.json following this:
https://github.com/Developer-Plexscape/cesium-angular-example/blob/master/angular.json

my angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "cesium-test-last": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "outputPath": "dist/cesium-test-last",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              {
                "glob": "**/*",
                "input": "node_modules/cesium/Build/Cesium",
                "output": "/assets/cesium"
              }
            ],
            "styles": [
              "node_modules/cesium/Build/Cesium/Widgets/widgets.css",
              "src/styles.css"
            ],
            "scripts": [],
            "customWebpackConfig": {
              "path": "./extra-webpack.config.js"
            }
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          "options": {
            "browserTarget": "test-again-cesium:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "cesium-test-last:build:production"
            },
            "development": {
              "browserTarget": "cesium-test-last:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "cesium-test-last:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              {
                "glob": "**/*",
                "input": "node_modules/cesium/Build/Cesium",
                "output": "/assets/cesium"
              }
            ],
            "styles": [
              "node_modules/cesium/Build/Cesium/Widgets/widgets.css",
              "src/styles.css"
            ],
            "scripts": []
          }
        }
      }
    }
  }
}

then added a extra-webpack.config.js file in the root of the project following again this:
https://github.com/Developer-Plexscape/cesium-angular-example/blob/master/extra-webpack.config.js

my webpack extra config:

  resolve: {
    fallback: {
      fs: "empty",
      Buffer: false,
      http: "empty",
      https: "empty",
      zlib: "empty"
    }
  },
  module: {
    unknownContextCritical: false
  }
};

and added a simple angular module like this:

(window as any).CESIUM_BASE_URL = '/';

import * as Cesium from 'cesium';
import "cesium/Build/Cesium/Widgets/widgets.css";
Cesium.Ion.defaultAccessToken = 'xxxxxxxxx';

@Component({
  selector: 'app-cesium-map',
  templateUrl: './cesium-map.component.html',
  styleUrls: ['./cesium-map.component.css']
})
export class CesiumMapComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    const viewer = new Cesium.Viewer('cesiumContainer', {
      terrainProvider: Cesium.createWorldTerrain()
    });
  }
}

but still I have this error:


BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }

Do you know how can I solve this?

Suggestion: I really think the cesiumjs-quickstart page should at least point to a blog page with an updated description of the passages to make cesiumjs work with angular as a module. the infos found work (i think) only for older versions of angular/cesium

@ggetz
Copy link
Contributor

ggetz commented Oct 13, 2022

Hi @spiderdab, could you try out the updated recommended webpack configuration for CesiumJS?

I think the relevant part to the error you're seeing is

fallback: { "https": false, "zlib": false, "http": false, "url": false },

@spiderdab
Copy link
Author

Hi, thanks for your suggestion.
I've cloned the suggested repository and it works as expected, so I'll pass that configuration in Angular.

@ggetz
Copy link
Contributor

ggetz commented Oct 17, 2022

Glad to hear!

@ggetz ggetz closed this as completed Oct 17, 2022
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

2 participants