pastelsky / bundlephobia

🏋️ Find out the cost of adding a new frontend dependency to your project
https://bundlephobia.com
MIT License
8.92k stars 221 forks source link

BuildError: xml-template-literal fails to build. #773

Closed Olian04 closed 1 year ago

Olian04 commented 1 year ago

Package name

xml-template-literal

Entire (stringified) error that I see in my browser console

Export analysis failed due to  {
    "error": {
        "code": "BuildError",
        "message": "Failed to build this package.",
        "details": {
            "name": "BuildError"
        }
    }
} error: code: "BuildError"details: name: "BuildError"[[Prototype]]: Objectmessage: "Failed to build this package."[[Prototype]]: Object[[Prototype]]: Object
overrideMethod @ react_devtools_backend.js:2655
(anonymous) @ [...packageString]-8dec680ff2abc7e3.js:1
Promise.catch (async)
(anonymous) @ [...packageString]-8dec680ff2abc7e3.js:1
componentDidMount @ [...packageString]-8dec680ff2abc7e3.js:1
uX @ framework-3b5a00d5d7e8d93b.js:9
e @ framework-3b5a00d5d7e8d93b.js:9
(anonymous) @ framework-3b5a00d5d7e8d93b.js:9
oU @ framework-3b5a00d5d7e8d93b.js:9
ox @ framework-3b5a00d5d7e8d93b.js:9
x @ framework-3b5a00d5d7e8d93b.js:33
T @ framework-3b5a00d5d7e8d93b.js:33
Screenshot 2023-04-12 at 15 52 46
upteran commented 1 year ago

Hi, did investigate of this error and figure out it generates in webpack's enhanced-resolve module, with message below

 Package path . is not exported from package /tmp/tmp-build/packages/build-xml-template-literal-eih/node_modules/xml-template-literal (see exports field in /tmp/tmp-build/packages/build-xml-template-literal-eih/node_modules/xml-template-literal/package.json)

Probably problem in export field in xml-template-literal package.json file. Here found some good describe of example with this problem In my opinion, have two options to resolve:

Think second option faster, but mb it's some common case and need to improve package-build-stats config, but with this point maybe @pastelsky will help, because I may not know some details

cefn commented 1 year ago

How did you get visibility of the underlying error? I'm facing an anonymous BuildError Failed to build this package. https://bundlephobia.com/package/@watchable/store@0.9.0-alpha.2 which I'm happy to pursue further but not sure how I can see it failing on my machine as you did. Maybe i need "types" and "default" when I currently have just "import" and "require" but without being able to run the build procedure it's hard to tell.

upteran commented 1 year ago

@cefn I've run project and checked error middleware. I see the same error with your package Package path . is not exported from... You can check how it resolved with enhanced-resolve separately from bundlephobia, using only this module, for example, and test directly your module

Olian04 commented 1 year ago

Hi, did investigate of this error and figure out it generates in webpack's enhanced-resolve module, with message below

 Package path . is not exported from package /tmp/tmp-build/packages/build-xml-template-literal-eih/node_modules/xml-template-literal (see exports field in /tmp/tmp-build/packages/build-xml-template-literal-eih/node_modules/xml-template-literal/package.json)

Probably problem in export field in xml-template-literal package.json file. Here found some good describe of example with this problem In my opinion, have two options to resolve:

  • add conditionNames param to package-build-stats pack (where placed enhanced-resolve)
  • add to xml-template-literal default field inside exports field, for ex:
  "exports": {
    "import": "./dist/api.js",
    "require": "./legacy/umd.cjs",
    "types": "./dist/api.d.ts",
    "default": "./dist/api.js"
  },

Think second option faster, but mb it's some common case and need to improve package-build-stats config, but with this point maybe @pastelsky will help, because I may not know some details

Thank you @upteran. This seems to have resolved the build error. However the "Exports Analysis" remains empty. It just says "GZIP sizes of individual exports".

Screenshot 2023-05-02 at 18 03 11
cefn commented 1 year ago

@cefn I've run project and checked error middleware.

Thanks for your clear description of how to recreate the resolution issue we are experiencing! For the @watchable/store project I was able to fix it for https://bundlephobia.com/package/@watchable/store@0.9.0-alpha.3 by adding a "default" field to "exports" in the package.json in https://github.com/cefn/watchable/commit/e17c03ea80c917b1f93a3e25473925b63e8defd2

upteran commented 1 year ago

@Olian04 Maybe the problem is in the setting of the default field. I've seen in your last version exported .cjs bundle by default. But in the field type: "module" you tell that your package uses ES modules. And maybe it is confusing on analyzing because if I do not mistake it works with ES modules only and type gives this info, that's why no error, but default commonjs bundle gives an empty "Exports Analysis"

try to export by default ES modules, maybe it can help

Olian04 commented 1 year ago

@upteran that resolves it. Thank you.