solidjs icon indicating copy to clipboard operation
solidjs copied to clipboard

[Bug] package has "type": "module", but only commonjs is published, causing problems

Open dylang opened this issue 9 months ago • 3 comments

Describe the bug

A clear and concise description of what the bug is.

Steps to reproduce the behavior

  1. https://www.npmjs.com/package/storybook-solidjs-vite?activeTab=code
  2. In the package.json is "type": "module" and there is "import": "./dist/preset.mjs".
  3. There's a file called storybook-solidjs-vite/dist/preset.js that contains commonjs (module.exports).
  4. There's no file named storybook-solidjs-vite/dist/preset.mjs.

Resulting error in Node 22:

[SB] info => Cleaning outputDir: storybook-static
[SB] info => Loading presets
[SB] SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: storybook-solidjs-vite/preset.
[SB] 
[SB] Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.
[SB] 
[SB] If you believe this is a bug, please open an issue on Github.
[SB] 
[SB] ReferenceError: module is not defined
[SB]     at file:///project/node_modules/.pnpm/[email protected]_@[email protected][email protected]_stor_9bc8418f99ab4125250afe575d87f224/node_modules/storybook-solidjs-vite/dist/preset.js:1:1009
[SB]     at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35)
[SB]     at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:360:47)
[SB]     at loadESMFromCJS (node:internal/modules/cjs/loader:1385:24)
[SB]     at Module._compile (node:internal/modules/cjs/loader:1536:5)
[SB]     at node:internal/modules/cjs/loader:1706:10
[SB]     at Object.newLoader (/project/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:2262:9)
[SB]     at extensions..js (/project/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:4833:24)
[SB]     at Module.load (node:internal/modules/cjs/loader:1289:32)
[SB]     at Function._load (node:internal/modules/cjs/loader:1108:12)

Expected behavior

Either change package.json type to commonjs or publish the code as a module.

Screenshots and/or logs

Shown above

Environment

  • OS: MacOS, Linux
  • Node.js version: 22
  • NPM version: pnpm 10

Additional context

I wasn't able to reproduce this with the example in this repo, maybe because of how the yarn monorepo works and the source being available.

dylang avatar Mar 26 '25 16:03 dylang

This might be addressed by https://github.com/storybookjs/solidjs/pull/20.

dylang avatar Mar 26 '25 19:03 dylang

This package also fails in the latest Node 20. https://github.com/nodejs/node/pull/56927

dylang avatar Apr 03 '25 15:04 dylang

Well after yarn build in parent dir, I was able to cd into example and run yarn storybook Had to modify example/main.ts slightly

import { createRequire } from 'module'; // Import createRequire

const require = createRequire(import.meta.url); // Create a require function

Was giving me this error before.

PS G:\dev\boop\solidjs\example> yarn storybook
@storybook/core v9.0.0-alpha.1

SB_CORE-SERVER_0007 (MainFileEvaluationError): Storybook couldn't evaluate your .storybook\main.ts file.

Original error:
ReferenceError: require is not defined
    at getAbsolutePath (\.storybook\main.ts:10:18)
    at \.storybook\main.ts:15:5

Node: v23.11.0 Windows 10.

LiamKarlMitchell avatar Apr 07 '25 11:04 LiamKarlMitchell