Skip to content

Bug: Cannot read properties of null (reading 'moduleSideEffects') #1913

@ptrxyz

Description

@ptrxyz
  • Rollup Plugin Name: commonjs
  • Rollup Plugin Version: 28.0.7
  • Rollup Version: 4.52.5
  • Operating System (or Browser): Linux (Arch btw)
  • Node Version: Bun 1.3.0; also present on Node v24.9.0
  • Link to reproduction (⚠️ read below): https://github.com/ptrxyz/rollup-bug-report

Expected Behavior

The link provided points to a minimal example, do this to reproduce:

  • checkout the repo, npm install, npm build
  • this should not fail

Actual Behavior

  • i get the following error:
> Using @sveltejs/adapter-node
error during build:
TypeError: Cannot read properties of null (reading 'moduleSideEffects')
    at file:///tmp/test/node_modules/@rollup/plugin-commonjs/dist/es/index.js:854:77
    at Array.map (<anonymous>)
    at file:///tmp/test/node_modules/@rollup/plugin-commonjs/dist/es/index.js:833:31
    at async rewriteRequireExpressionsAndGetImportBlock (file:///tmp/test/node_modules/@rollup/plugin-commonjs/dist/es/index.js:1397:28)
    at async transformCommonjs (file:///tmp/test/node_modules/@rollup/plugin-commonjs/dist/es/index.js:1986:23)
    at async transform (file:///tmp/test/node_modules/rollup/dist/es/shared/node-entry.js:21139:16)
    at async ModuleLoader.addModuleSource (file:///tmp/test/node_modules/rollup/dist/es/shared/node-entry.js:21352:36)

Additional Information

The repo is a minimal SvelteKit application created with the sv create tool with a single added dependency that demonstrates the problem by simply importing it: (@paralleldrive/cuid): https://github.com/ptrxyz/rollup-bug-report/blob/72cf37c9bd17c5c1541da2aae2ba9faf1bf36e0b/src/routes/%2Bpage.server.ts#L2

The issue seems that CUID2 imports @noble/hashes as a peer dependency, specifically node_modules/@noble/hashes/cryptoNode.js. There you will find the offending import in line 12:

// node_modules/@noble/hashes/cryptoNode.js
...
const nc = require("node:crypto");
...

This require seems to break with RollUp since version >4.48 with the introduction of https://github.com/rollup/plugins/blob/1935e9e3e2fa1e68b25f5d16fd6007cf9fe205fb/packages/commonjs/src/resolve-require-sources.js#L196C11-L208C12

Note: I was not able to reproduce this bug when directly importing @noble/hashes into my app, so i suppose it has to do with the CUID2 detour?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions