JeremyRH / storybook-addon-code-editor

A Storybook add-on for live editing stories.
https://jeremyrh.github.io/storybook-addon-code-editor
MIT License
22 stars 8 forks source link

`require.resolve` will fail for ESM packages without specific `exports` entry #20

Closed wintercounter closed 1 year ago

wintercounter commented 1 year ago

Using require.resolve will fail on ESM packages having no package.json in their exports field (and most of them won't have it).

https://github.com/JeremyRH/storybook-addon-code-editor/blob/c7aabd3c01000e5a453af7e9eca207eb9d2ab206/getStaticDirs.js#L8

Instead, you can resolve the entry file, and use that path to resolve the package dir.

const entryDir = path.dirname(require.resolve(packageName))
const packageDir= moduleName.replace(new RegExp(`^(.*${packageName})(.*)$`), (_, dir) => dir)

I have this issue use monaco-tailwindcss@0.6.0