I was trying to compile memfs package for the browser. Webpack build is working just fine, but I want to bundle it with rollup and I constanlty getting "Uncaught ReferenceError: exports is not defined".
I've made repl.it example with my config
For someone who do not wanna use repl.it, here are my files:
// rollup.config.js
import resolve from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import nodePolyfills from "rollup-plugin-polyfill-node";
export default {
input: 'index.js',
output: {
dir: "dist",
format: 'esm',
},
plugins:[
nodePolyfills(),
resolve({
preferBuiltins: false,
browser: true,
}),
commonjs(),
],
}
File I am trying to process:
// index.js
import { fs } from "memfs";
let code = `
console.log("hello, world!");
`;
fs.writeFileSync("./code", code);
console.log(fs.readFileSync("./code"));
I've tried many commonjs options and nothing worked for me.
Maybe I am missing something?
Thanks =)
Okay, I've figured it out. I've had a wrong plugin order.
The right order is:
export default {
// all previous settings
plugins: [
resolve({
preferBuiltins: false,
browser: true,
}),
commonjs(),
nodePolyfills(),
]
};