Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dylang opened this issue Mar 26, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@dylang
Copy link

dylang commented Mar 26, 2025

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 dylang added the bug Something isn't working label Mar 26, 2025
@dylang
Copy link
Author

dylang commented Mar 26, 2025

This might be addressed by #20.

@dylang
Copy link
Author

dylang commented Apr 3, 2025

This package also fails in the latest Node 20. nodejs/node#56927

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Apr 7, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants