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

"'import.meta' cannot be used outside of module code" error when upgrading to meteor 3 #45

Open
kfritsch opened this issue Oct 14, 2024 · 0 comments

Comments

@kfritsch
Copy link

I get a build error when upgrading to meteor 3.0.3 with minifier version 5.3.1. It did not happen with meteor 2.10.0 on the same version and there is also no error when using the default minifier and meteor 3.0.3.

Error message
     While minifying app code:

   /Users/kaifritsch/.meteor/packages/zodern_standard-minifier-js/.5.3.1.13xodu.yv0c3++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/fastMinifier/node_modules/meteor-package-install-swc/.swc/node_modules/@swc/core/index.js:110:29: 
   × 'import.meta' cannot be used outside of module
   code.
   ╭─[567:1]
   567 │   if (typeof WorkerGlobalScope < "u" && self instanceof
   WorkerGlobalScope) {
   568 │     if (typeof o != "string")
   569 │       throw Error("corePath should be a string!");
   570 │     const y = new URL(o, import.meta.url).href, m = await
   W(
   ·                          ───────────
   571 │       y,
   572 │       "application/javascript"
   573 │     ), v = await W(
   ╰────
   
   × 'import.meta' cannot be used outside of module
   code.
   ╭─[595:1]
   595 │   }
   596 │   if (typeof o != "string")
   597 │     throw Error("corePath should be a string!");
   598 │   const p = new URL(o, import.meta.url).href, c = await
   W(
   ·                        ───────────
   599 │     p,
   600 │     "application/javascript"
   601 │   ), l = await W(
   ╰────
   
   × 'import.meta' cannot be used outside of module
   code.
   ╭─[632:1]
   632 │   }, p.readAsArrayBuffer(o);
   633 │ }), Re = async (o) => {
   634 │   let f = o;
   635 │   return typeof o > "u" ? new Uint8Array() : (typeof o ==
   "string" ? /data:_data\/([a-zA-Z]*);base64,([^"]*)/.test(o) ? f =
   atob(o.split(",")[1]).split("").map((s) => s.charCodeAt(0)) : f = await
   (await fetch(new URL(o, import.meta.url).href)).arrayBuffer() : (o
   instanceof File || o instanceof Blob) && (f = await Te(o)), new
   Uint8Array(f));
   ·
   
   ───────────
   636 │ }, Ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */
   Object.defineProperty({
   637 │   __proto__: null,
   638 │   defaultOptions: Se,
   ╰────
   
   
   Caused by:
   0: failed to parse input file
   1: Syntax Error while minifying
   dynamic/node_modules/react-audio-voice-recorder/dist/index-1c988149.js
   at Compiler.minifySync
   (/Users/kaifritsch/.meteor/packages/zodern_standard-minifier-js/.5.3.1.13xodu.yv0c3++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/fastMinifier/node_modules/meteor-package-install-swc/.swc/node_modules/@swc/core/index.js:110:29)
   at Object.minifySync
   (/Users/kaifritsch/.meteor/packages/zodern_standard-minifier-js/.5.3.1.13xodu.yv0c3++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/fastMinifier/node_modules/meteor-package-install-swc/.swc/node_modules/@swc/core/index.js:373:21)
   at MeteorBabelMinifier._minifyWithSwc
   (packages/fastMinifier_plugin.js:72:16)
   at MeteorBabelMinifier.minifyOneFile
   (packages/fastMinifier_plugin.js:121:19)
   at packages/zodern_caching-minifier.js:77:23
   at Function.Profile.time (packages/zodern_caching-minifier.js:34:5)
   at MeteorBabelMinifier.minifyFile
   (packages/zodern_caching-minifier.js:76:15)
   at packages/fastMinifier_plugin.js:183:27
   at Function.Profile.time (packages/fastMinifier_plugin.js:35:7)
   at packages/fastMinifier_plugin.js:182:17
   at Array.forEach (<anonymous>)
   at MeteorBabelMinifier.<anonymous> (packages/fastMinifier_plugin.js:163:9)
   at MeteorBabelMinifier.processFilesForBundle
   (packages/fastMinifier_plugin.js:31:21)
   
   
=> Your application has errors. Waiting for file change.

The reason seems to be a reference to import.meta in the package ffmpeg, which is dynamically imported by the package react-audio-voice-recorder

Its reproducible in a base meteor react app, with just react-audio-voice-recorder installed and imported. You mentioned on a meteor ticket that "Meteor has never supported import.meta", but since it is working in meteor 2.10 and also in 3.0.3 with the standard minifier, I thought it might be fixable in this case.

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

1 participant