laravel-vite-plugin recently added support for ESM, e.g. so one can set "type": "module" in the root package.json of a laravel project. This gives a hint to node that ESM should be assumed for all *.js files.
It seems tsup as configured for this project over bundles dependencies, and results in a ESM export that cannot be used in a ESM laravel project.
npm run build
failed to load config from /my-laravel-project/vite.config.js
error during build:
Error: Dynamic require of "events" is not supported
at file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:12:9
at Object.<anonymous> (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:5595:16)
at node_modules/xml2js/lib/parser.js (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:5951:8)
at __require2 (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:15:50)
at Object.<anonymous> (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:5975:16)
at node_modules/xml2js/lib/xml2js.js (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:5990:8)
at __require2 (file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:15:50)
at file:///my-laravel-project/node_modules/@infrasym/laravel-favicon-vite-plugin/dist/index.js:5996:29
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
As a workaround you can change tsup to tsup-node in the package.jsonbuild script. Since favicons is only a devDependency here that needed to be installed as well in my project.
This could just be a weird tsup bug, but at the same time wouldn't it be best to avoid bundling so many dependencies in the first place in the outputted dist? Right now the 2 outputted dist files index.cjs and index.js have a size of ~500 KB combined, instead of ~7 KB with tsup-node (of course this ignores the size of the favicons package that may need to be installed).
laravel-vite-plugin recently added support for ESM, e.g. so one can set
"type": "module"
in the rootpackage.json
of a laravel project. This gives a hint to node that ESM should be assumed for all*.js
files.It seems
tsup
as configured for this project over bundles dependencies, and results in a ESM export that cannot be used in a ESM laravel project.As a workaround you can change
tsup
totsup-node
in thepackage.json
build
script. Sincefavicons
is only adevDependency
here that needed to be installed as well in my project.This could just be a weird tsup bug, but at the same time wouldn't it be best to avoid bundling so many dependencies in the first place in the outputted dist? Right now the 2 outputted dist files
index.cjs
andindex.js
have a size of ~500 KB combined, instead of ~7 KB withtsup-node
(of course this ignores the size of thefavicons
package that may need to be installed).