systemjs / systemjs

Dynamic ES module loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

package.json type=script cause esbuild failed to bundle

wenerme opened this issue · comments

due to type=script

# report content type as application/node
curl -I https://cdn.jsdelivr.net/npm/systemjs | grep content-type

esbuild failed to bundle systems, can not recongnize script type, bundled as json

✘ [ERROR] JSON does not support comments

    ../../node_modules/systemjs/dist/system.min.js:1:0:
      1 │ /*!
        ╵ ~~~

✘ [ERROR] Unexpected "!"

    ../../node_modules/systemjs/dist/system.min.js:4:0:
      4 │ !function(){function e(e,t){return(t||"")+" (SystemJS Error#"+e+" https://github.com/systemjs/sy...
        ╵ ^

✘ [ERROR] Unexpected "new"

    ../../node_modules/systemjs/dist/extras/dynamic-import-maps.min.js:1:0:
      1 │ new MutationObserver((function(e){for(var t=0;t<e.length;t++){var r=e[t];if("childList"===r.type...
        ╵ ~~~

✘ [ERROR] Unexpected "!"

    ../../node_modules/systemjs/dist/extras/module-types.min.js:1:0:
      1 │ !function(){function e(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(i,"/")),"/"===e[0]&&"/"===e[1]...
        ╵ ^

edit

the error is reported by vite, using esbuild only report

 The "type" field must be set to either "commonjs" or "module".

but vite some how failed when updating dependencies.

This seems like an esbuild issue. Very specifically, type "script" is useful as distinct from "commonjs" and "module" to distinguish CommonJS (which can be converted into ESM) from actual scripts (which can run on the web as scripts not ES modules, and without any conversion).