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

Build failed while creating shared libraries #508

Closed
rbuerschgens opened this issue Mar 13, 2024 · 9 comments
Closed

Build failed while creating shared libraries #508

rbuerschgens opened this issue Mar 13, 2024 · 9 comments

Comments

@rbuerschgens
Copy link

We want to use in our project Fabric.js, but building the application after adding fabric as a dependency always fails with the error:

X [ERROR] Could not resolve "path"

    (disabled):node_modules/fabric/node_modules/jsdom/lib/api.js:3:21:
      3 │ const path = require("path");
        ╵                      ~~~~~~

  The package "path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "path"

    (disabled):node_modules/fabric/node_modules/jsdom/lib/jsdom/utils.js:3:21:
      3 │ const path = require("path");
        ╵                      ~~~~~~

  The package "path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "fs"

    (disabled):node_modules/fabric/node_modules/jsdom/lib/api.js:4:19:
      4 │ const fs = require("fs").promises;
        ╵                    ~~~~

  The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "fs"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/browser/resources/resource-loader.js:3:19:
      3 │ const fs = require("fs");
        ╵                    ~~~~

  The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/browser/resources/resource-loader.js:6:12:
      6 │ } = require("url");
        ╵             ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "http"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:3:21:
      3 │ const http = require("http");
        ╵                      ~~~~~~

  The package "http" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "https"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:4:22:
      4 │ const https = require("https");
        ╵                       ~~~~~~~

  The package "https" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "http"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/agent-factory.js:3:21:
      3 │ const http = require("http");
        ╵                      ~~~~~~

  The package "http" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "stream"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:7:12:
      7 │ } = require("stream");
        ╵             ~~~~~~~~

  The package "stream" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "https"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/agent-factory.js:4:22:
      4 │ const https = require("https");
        ╵                       ~~~~~~~

  The package "https" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/agent-factory.js:7:12:
      7 │ } = require("url");
        ╵             ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "zlib"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:8:21:
      8 │ const zlib = require("zlib");
        ╵                      ~~~~~~

  The package "zlib" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "path"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/utils.js:3:21:
      3 │ const path = require("path");
        ╵                      ~~~~~~

  The package "path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "util"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:3:21:
      3 │ const util = require("util");
        ╵                      ~~~~~~

  The package "util" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "net"

    node_modules/fabric/node_modules/https-proxy-agent/dist/agent.js:38:38:
      38 │ const net_1 = __importDefault(require("net"));
         ╵                                       ~~~~~

  The package "net" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "net"

    node_modules/fabric/node_modules/http-proxy-agent/dist/agent.js:38:38:
      38 │ const net_1 = __importDefault(require("net"));
         ╵                                       ~~~~~

  The package "net" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "tls"

    node_modules/fabric/node_modules/https-proxy-agent/dist/agent.js:39:38:
      39 │ const tls_1 = __importDefault(require("tls"));
         ╵                                       ~~~~~

  The package "tls" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "tls"

    node_modules/fabric/node_modules/http-proxy-agent/dist/agent.js:39:38:
      39 │ const tls_1 = __importDefault(require("tls"));
         ╵                                       ~~~~~

  The package "tls" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "assert"

    node_modules/fabric/node_modules/https-proxy-agent/dist/agent.js:41:41:
      41 │ const assert_1 = __importDefault(require("assert"));
         ╵                                          ~~~~~~~~

  The package "assert" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "http"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:3:34:
      3 │ const HTTP_STATUS_CODES = require("http").STATUS_CODES;
        ╵                                   ~~~~~~

  The package "http" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "child_process"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:6:12:
      6 │ } = require("child_process");
        ╵             ~~~~~~~~~~~~~~~

  The package "child_process" wasn't found on the file system but is built into node. Are you trying
  to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/navigator/NavigatorConcurrentHardware-impl.js:3:19:
      3 │ const os = require("os");
        ╵                    ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "fs"

    node_modules/fabric/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:3:19:
      3 │ const fs = require("fs");
        ╵                    ~~~~

  The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

An unhandled exception occurred: Build failed with 23 errors:
(disabled):node_modules/fabric/node_modules/jsdom/lib/api.js:3:21: ERROR: Could not resolve "path"
(disabled):node_modules/fabric/node_modules/jsdom/lib/api.js:4:19: ERROR: Could not resolve "fs"
(disabled):node_modules/fabric/node_modules/jsdom/lib/jsdom/utils.js:3:21: ERROR: Could not resolve "path"
node_modules/fabric/node_modules/http-proxy-agent/dist/agent.js:38:38: ERROR: Could not resolve "net"
node_modules/fabric/node_modules/http-proxy-agent/dist/agent.js:39:38: ERROR: Could not resolve "tls"
...

We tried adding 'fabric' to the devDependencies and also put it in the skip array of our federation.config.js. That does not change anything.

The versions we are using are:
@angular/cli: 17.2.0
@angular-architects/native-federation: 17.1.6
fabric: 5.3.0

Our package.json looks like this:

{
  "name": ...,
  "version": "0.0.0",
  "scripts": {},
  "private": true,
  "dependencies": {
    "@angular-architects/native-federation": "^17.1.6",
    "@angular-architects/ngrx-toolkit": "^0.0.4",
    "@angular/animations": "^17.2.1",
    "@angular/cdk": "^17.2.0",
    "@angular/common": "^17.2.1",
    "@angular/compiler": "^17.2.1",
    "@angular/core": "^17.2.1",
    "@angular/forms": "^17.2.1",
    "@angular/platform-browser": "^17.2.1",
    "@angular/platform-browser-dynamic": "^17.2.1",
    "@angular/router": "^17.2.1",
    "@ngrx/operators": "^17.1.0",
    "@ngrx/signals": "^17.1.0",
    "@ngrx/store-devtools": "^17.1.0",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "es-module-shims": "^1.8.2",
    "ngx-translate-multi-http-loader": "^17.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "^0.14.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^17.2.0",
    "@angular/cli": "^17.2.0",
    "@angular/compiler-cli": "^17.2.1",
    "@types/fabric": "^5.3.7",
    "@types/jasmine": "~5.1.0",
    "chart.js": "^4.4.1",
    "fabric": "^5.3.0",
    "jasmine-core": "~5.1.0",
    "jsdom": "^24.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "prettier": "^3.2.5",
    "primeflex": "^3.3.1",
    "primeicons": "^6.0.1",
    "primeng": "^17.7.0",
    "quill": "^1.3.7",
    "typescript": "~5.2.2"
  }
}

And our federation.config.js like this:

const {
  withNativeFederation,
  shareAll,
} = require("@angular-architects/native-federation/config");

module.exports = withNativeFederation({
  name: "invoice-workflow-frontend",

  exposes: {
    ...
  },

  shared: {
    ...shareAll({
      singleton: true,
      strictVersion: true,
      requiredVersion: "auto",
    }),
  },

  skip: [
    "rxjs/ajax",
    "rxjs/fetch",
    "rxjs/testing",
    "rxjs/webSocket",
    "fabric",
    "jsdom",
    // Add further packages you don't need at runtime
  ],
});

What I don't understand is, that the build still tries to build the fabric library, do I miss something?

@manfredsteyer
Copy link
Contributor

It seems like this is because the package contains its own build scripts (build.js, publish.js, publish.next.js). It seems like these files are recognized as separate entry points that NF tries to compile. I need to investigate why this is the case.

@joepeace01
Copy link

@manfredsteyer Is there any news about this topic ? I'm in a similar situation where package I want to skip are still displayed in the console as errors, and this only appears with native-federation builder. Also when bootstrapping the application, it doesn't fetch the remoteEntry.json I have in the manifest file. But again when I'm not using native federation builder, I can my manifestFile being loaded, it just does not load my micro front end past that point.

@manfredsteyer
Copy link
Contributor

So, for now, it's about identifying the entry points that cause such issues and skipping them by adding them to the skip list.

@mguay22
Copy link

mguay22 commented Aug 19, 2024

We're still seeing this same issue with

"@angular-architects/native-federation": "^17.0.7"

Despite updating the skip array with the dependencies to bypass from compilation, it doesn't work

module.exports = withNativeFederation({
  name: 'ngp',

  exposes: {
    './Component': './projects/ngp/src/lib/app.component.ts'
  },

  shared: {
    ...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
  },

  skip: [
    'rxjs/ajax',
    'rxjs/fetch',
    'rxjs/testing',
    'rxjs/webSocket',
    "@apollo",
    "@apollo/client",
    "react"    
    // Add further packages you don't need at runtime
  ]

  // Please read our FAQ about sharing libs:
  // https://shorturl.at/jmzH0
});

✘ [ERROR] Could not resolve "react"

node_modules/@apollo/client/react/hooks/useReactiveVar.js:1:23:
  1 │ import * as React from "react";
    ╵                        ~~~~~~~

You can mark the path "react" as external to exclude it from the bundle, which will remove this
error and leave the unresolved path in the bundle.

1 of 83 errors shown (disable the message limit with --log-limit=0)

Is anyone else still seeing this? Will perhaps try upgrading to the latest version.

@sajay-g
Copy link

sajay-g commented Nov 1, 2024

@mguay22, were you able to find a solution to this issue?

I'm encountering the same problem with "@angular-architects/native-federation": "^18.2.2".

Any assistance would be greatly appreciated.

Thank you for your time!

@rainerhahnekamp
Copy link
Collaborator

@sajay-g, @mguay22 @joepeace01 you can help us.

If this is a persisting issue, please reopen or create a new issue and provide a StackBlitz example. An example that already contains the issue saves us a lot of time trying to reproduce it.

Thanks guys!

@sajay-g
Copy link

sajay-g commented Nov 5, 2024

@rainerhahnekamp I have created issue 683

@joepeace01
Copy link

Hi, yes I was able to resolve this issue by using a regular expression:
skip:
[
/^@myLibrary/,
]

@augustoflow
Copy link

augustoflow commented Nov 15, 2024

@rainerhahnekamp @sajay-g @mguay22, do you have any news about this issue? It's the same here at Federation 18.2.2, and we also have problems with Apollo dependencies. Putting them on the skip list is not working.

Angular 18.2 w/ Vite and Module Federation

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

No branches or pull requests

7 participants