ThatOpen / web-ifc-three

The official IFC Loader for Three.js.
https://ifcjs.github.io/info/
MIT License
521 stars 133 forks source link

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted #191

Open Markus-x64 opened 3 months ago

Markus-x64 commented 3 months ago

Issue

I recently updated web-ifc-three to the latest version hoping to resolve this critical dependency warning without luck:

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/web-ifc-three/IFCLoader.js 1:0-34 2:0-233 112:7-15 113:7-24 188:68-93 661:10-26 667:10-43 673:10-35 679:10-34 685:10-29 812:70-80 883:62-72 1099:74-85 1964:7-15 1965:7-24 2386:15-28 2462:27-40 2598:27-40

Delving deeper, I discovered that the issue originates from web-ifc. There are already two issues on the web-ifc repository discussing this problem, and it was resolved in May 2023 with version 0.0.41.

After some investigation, I found that both web-ifc-three@0.0.125 and web-ifc-three@0.0.126 from the Node Package Manager still rely on web-ifc@^0.0.39, which causes the critical dependency warning.

Here on the web-ifc-three GitHub repository, the package-lock.json for the main branch (version 0.0.125) specifies:

"node_modules/web-ifc": {
  "version": "0.0.41",
  "resolved": "https://registry.npmjs.org/web-ifc/-/web-ifc-0.0.41.tgz",
  "integrity": "sha512-rSucJcwWDw6jrfxPu77jVcpCU6otMd3qWYsH+6L3nr5jJVr4S1O5rAZfkKNlpBM5m0mDvSHU3DzXm9SXfGqBkw=="
}

Steps Taken to Resolve the Issue:

I tried various tricks with npm, but I wasn't able to override web-ifc version 0.0.39.

Finally, I resolved the critical dependency warnings by forcing web-ifc version 0.0.41 through modifying my package-lock.json. Here are the steps I took:

  1. Start with a clean package.json:
    {
     "name": "your-project-name",
     "version": "1.0.0",
     "dependencies": {
       "web-ifc-three": "0.0.125"
     }
    }
  2. Remove existing node_modules and package-lock.json:
    rm -rf node_modules package-lock.json
  3. Run npm install:
    npm install
  4. Install web-ifc@0.0.41 to obtain the "resolved" and "integrity" values. Then uninstall it and repeated steps 2 and 3:
    npm install web-ifc@0.0.41 --save
    npm uninstall web-ifc
  5. Open package-lock.json and manually update all occurrences of web-ifc to version 0.0.41:
    "web-ifc": {
     "version": "0.0.41",
     "resolved": "https://registry.npmjs.org/web-ifc/-/web-ifc-0.0.41.tgz",
     "integrity": "sha512-..."
    }
  6. Reinstall dependencies:
    npm install

Request

Could you update the web-ifc dependency in web-ifc-three to ^0.0.41 in the npm package?