davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
301 stars 22 forks source link

Error when having type: module in package.json #82

Open Jinjiang opened 7 months ago

Jinjiang commented 7 months ago

Reproduction: https://github.com/Jinjiang/reproductions/tree/vite-node-polyfill-20240214

pnpm install
pnpm build

error log:

error during build:
RollupError: "existsSync" is not exported by "node_modules/.pnpm/node-stdlib-browser@1.2.0/node_modules/node-stdlib-browser/esm/mock/empty.js", imported by "src/index.ts".
...

if works if you remove "type": "module" from package.json

Jinjiang commented 7 months ago

Update: changing

import { existsSync, readFileSync } from 'fs'

into

import fs from 'fs'
const { existsSync, readFileSync } = fs

works. Only named exports don't.