Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when build. mime Error #102

Open
Sundayuu opened this issue Dec 4, 2023 · 5 comments
Open

when build. mime Error #102

Sundayuu opened this issue Dec 4, 2023 · 5 comments

Comments

@Sundayuu
Copy link

Sundayuu commented Dec 4, 2023

var lite = require('mime/lite');

       ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/registry.npmmirror.com+mime@4.0.0/node_modules/mime/dist/src/index_lite.js from /root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/registry.npmmirror.com+rollup-plugin-serve@3.0.0/node_modules/rollup-plugin-serve/dist/index.cjs not supported.

Instead change the require of index_lite.js in /root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/registry.npmmirror.com+rollup-plugin-serve@3.0.0/node_modules/rollup-plugin-serve/dist/index.cjs to a dynamic import() which is available in all CommonJS modules.

at Object.<anonymous> (/root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/registry.npmmirror.com+rollup-plugin-serve@3.0.0/node_modules/rollup-plugin-serve/dist/index.cjs:7:12)

at Object.<anonymous> (/root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/@toolkit+cli-plugin-rollup@1.1.0_@babel+core@7.12.13_tslib@2.4.0_typescript@4.7.4/node_modules/@toolkit/cli-plugin-rollup/lib/dev.config.js:6:15)

at Object.<anonymous> (/root/workspace/node16-pnpm8-build/repo/node_modules/.pnpm/@toolkit+cli-plugin-rollup@1.1.0_@babel+core@7.12.13_tslib@2.4.0_typescript@4.7.4/node_modules/@toolkit/cli-plugin-rollup/bin/toolkit-cli-service.js:3:19) {

code: 'ERR_REQUIRE_ESM'

}

@thgh
Copy link
Owner

thgh commented Dec 7, 2023

Does it work using this version range ^2 in package.json?

@ythvg
Copy link

ythvg commented Dec 8, 2023

reason: the mime version 4 is now pure esm . It cannot be require()'d from CommonJS.
solve: use import/export in rollup.config.js and set "type": "module" in your package.json

@thgh
Copy link
Owner

thgh commented Dec 9, 2023

For your information:
rollup-plugin-serve@^1 uses mime 2
rollup-plugin-serve@^2 uses mime 3
rollup-plugin-serve@^3 uses mime 4

@drushbrook
Copy link

@thgh - according to the most downloaded versions of rollup-plugin-serve as reported by the npm version history (https://www.npmjs.com/package/rollup-plugin-serve?activeTab=versions)
rollup-plugin-serve@1.0.1 uses mime>=2.0.3 which to my understanding will now use mime@4.0.0
rollup-plugin-serve@1.1.0 uses mime>=2.4.6 which to my understanding will now use mime@4.0.0
rollup-plugin-serve@2.0.2 uses mime>=2.4.6 which to my understanding will now use mime@4.0.0
rollup-plugin-serve@2.0.3 uses mime^3 which to my understanding will now use mime@3.0.0
rollup-plugin-serve@latest (3.0.0) uses mime^4

unfortunately I'm using a package that has a subdependancy for rollup-plugin-serve@^1.0.1 hence running into a similar mime error.

@thgh
Copy link
Owner

thgh commented Dec 14, 2023

Sure, published the patch in rollup-plugin-serve@1.1.1 just now

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

No branches or pull requests

4 participants