Closed FlandreDaisuki closed 5 months ago
Sorry to bother you about this, but what do I need to change to support these changes?
Previously I was doing
import metablock from "rollup-plugin-userscript-metablock";
but now I get SyntaxError: The requested module 'rollup-plugin-userscript-metablock' does not provide an export named 'default'
sorry for inconvenience, I'll investigate this problem asap.
@cvzi I found that the problem is node resolution in package.json
.
I've tried to fix it in v0.4.1 and tested in my use-cases.
Yes it works, thank you for the quick response!
It still doesn't work with require
e.g. const metablock = require('rollup-plugin-userscript-metablock')
const metablock = require('rollup-plugin-userscript-metablock')
^
Error [ERR_REQUIRE_ESM]: require() of ES Module \node_modules\rollup-plugin-userscript-metablock\dist\rollup-plugin-userscript-metablock.common.js from my.js not supported.
rollup-plugin-userscript-metablock.common.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename rollup-plugin-userscript-metablock.common.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in node_modules\rollup-plugin-userscript-metablock\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (my.js:8:19) {
code: 'ERR_REQUIRE_ESM'
}
I tried the suggestion in the error and manually renamed the file dist/rollup-plugin-userscript-metablock.common.js
to dist/rollup-plugin-userscript-metablock.common.cjs
and that solves it.
@cvzi Thanks so much for the report!! ❤️ I just update to v0.4.2 and update the examples to following 3 situations:
package.json
& use commonjs in rollup.config.js
build with no special flagtype: "module"
in package.json
& use esmodule in rollup.config.js
build with no special flagpackage.json
& use esmodule in rollup.config.js
build with --bundleConfigAsCjs
flagI hope I can cover all possible situations.
test!: replace mocha with vitest build!: replace npm with pnpm build!: update deps