area17 / blast

Storybook for Laravel Blade 🚀
https://dev.to/area17/getting-started-with-blast-storybook-for-laravel-blade-c5c
Apache License 2.0
262 stars 37 forks source link

Feature Request: Support `tailwind.config.js` in default ESM format #98

Closed johnbacon closed 6 months ago

johnbacon commented 10 months ago

In my recent Laravel + Tailwind installation, tailwind.config.js is included as an ES Module. This causes the following error on blast:launch and blast:publish:

php artisan blast:launch
0/2 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] Reusing npm dependencies...
1/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░] Generating Stories...Error [ERR_REQUIRE_ESM]: require() of ES Module /e/server/gigsalad-laravel/laravel/tailwind.config.js 
from /e/server/gigsalad-laravel/laravel/vendor/area17/blast/src/resolveTailwindConfig.js not supported.
Instead change the require of tailwind.config.js in /e/server/gigsalad-laravel/laravel/vendor/area17/blast/src/resolveTailwindConfig.js to a dynamic import() 
which is available in all CommonJS modules.
    at Object.<anonymous> (/e/server/gigsalad-laravel/laravel/vendor/area17/blast/src/resolveTailwindConfig.js:6:18) {
  code: 'ERR_REQUIRE_ESM'
}

It appears Tailwind generates an ESM config file by default depending on other settings in your project: https://tailwindcss.com/docs/configuration#using-esm-or-type-script

And it looks like Laravel has configured package.json as type: module since version 10.2: https://github.com/laravel/laravel/blob/25070a3ffb175c15b59cd7f12289a9648165bba3/CHANGELOG.md?plain=1#L34

By supporting both ESM and CommonJS formats, Blast will be more able to provide documentation "out of the box" going forward.

andresgutgon commented 6 months ago

Maybe now that Tailwind v3.4.0 supports ESM is easier to fix this

By changing require by import here

 const config = import(process.env.CONFIGPATH)

It looks my ESM tailwind config loads correctly