esbuild-rails icon indicating copy to clipboard operation
esbuild-rails copied to clipboard

Add `chokidar` to install step and fix `esbuild.config.mjs` file extension

Open marcoroth opened this issue 11 months ago • 4 comments

While migrating an app to use esbuild-rails I noticed the following to issues. If you don't install chokidar yourself to your app it would fail to build:

❯ yarn build
yarn run v1.22.19
warning ../package.json: No license field
$ node esbuild.config.mjs
node:internal/modules/esm/resolve:838
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chokidar' imported from 
[project]/esbuild.config.mjs
    at packageResolve (node:internal/modules/esm/resolve:838:9)
    at moduleResolve (node:internal/modules/esm/resolve:907:18)
    at defaultResolve (node:internal/modules/esm/resolve:1037:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:650:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:599:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:582:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:241:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:132:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

~~I'm almost wondering if the esbuild-rails package itself should depend on chokidar.~~ Edit: I guess we can just add an note to the README.

Additionally I also updated the esbuild config file extension in the README.

marcoroth avatar Dec 23 '24 16:12 marcoroth

esbuild-rails itself doesn't use chokidar.

The example script does use it to show how to implement automatic reloading though.

excid3 avatar Dec 23 '24 16:12 excid3

Ah right, fair enough. Do you want to keep it in the install instructions or should I move it out of the main yarn/npm i code block?

marcoroth avatar Dec 23 '24 16:12 marcoroth

That seems good to me. 👍

Should we mention it's optional somewhere?

excid3 avatar Dec 23 '24 16:12 excid3

Or is there any way to lazy import chokidar like we can do in Ruby? 🤔

excid3 avatar Dec 23 '24 16:12 excid3