Skip to content

fix: use correct module type for node/ (cjs)#865

Open
IvanVishnevskiy wants to merge 1 commit into
kylebarron:mainfrom
IvanVishnevskiy:ivan/fix-cjs-node-import
Open

fix: use correct module type for node/ (cjs)#865
IvanVishnevskiy wants to merge 1 commit into
kylebarron:mainfrom
IvanVishnevskiy:ivan/fix-cjs-node-import

Conversation

@IvanVishnevskiy

@IvanVishnevskiy IvanVishnevskiy commented Jun 24, 2026

Copy link
Copy Markdown

Currently, we build esm, bundler and node (CJS) targets. However, the main package.json inherits { "type": "module" } set by the bundler output during copying in

jq -s '.[0] * .[1]' templates/package.json tmp_build/bundler/package.json > pkg/package.json

This means that our CJS export node/ has type module so any CJS Node.JS application would fail to import it.

By simply adding {"type": "commonjs"} to node/package.json, we ensure that node can correctly resolve the right type for that target.

This fixes #798

@IvanVishnevskiy

IvanVishnevskiy commented Jun 24, 2026

Copy link
Copy Markdown
Author

Built the project locally and used npm link to verify - getting correct behavior now with Node.js 24.
With this code:

import { readParquet } from 'parquet-wasm';
console.log(readParquet);

Previously:

file:///home/<redacted>/parquet-wasm/pkg/node/parquet_wasm.js:3
imports['__wbindgen_placeholder__'] = module.exports;
                                      ^

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/<redacted>/parquet-wasm/pkg/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/<redacted>/parquet-wasm/pkg/node/parquet_wasm.js:3:39

After the fix:

[Function (anonymous)]

@github-actions

Copy link
Copy Markdown
Asset Size Compressed Size
report_pkg/async_full/parquet_wasm_bg.wasm 6.4MB 1.3MB
report_pkg/slim/parquet_wasm_bg.wasm 4.6MB 658KB
report_pkg/sync/parquet_wasm_bg.wasm 5.9MB 1.2MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NodeJS usage not working in ESM

1 participant