-
-
Notifications
You must be signed in to change notification settings - Fork 559
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
[@rollup/plugin-terser] esm module uses __filename #1366
Comments
@jakearchibald for future reference, please keep all bits of the templates in the issues. |
It felt redundant, but: Expected BehaviorRun without throwing an error. Actual BehaviorThrew the following error:
|
All good. @tada5hi is the lead for that plugin, so hopefully they see this soon |
For reference: I think I'm hitting this issue, when upgrading
|
I will take care of the problem ✌️ |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Hey @tada5hi, you might want to check this isomorphic EDIT: saw you raised #1367 for a fix |
@mxdvl that approach also throws an error with Node 16+, tested that last night |
To fix this issue for now. I put the below lines of code in my import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
global['__filename'] = __filename; |
Replace the deprecated rollup-plugin-terser with @rollup/plugin-terser. Then, for all packages in devDependencies, update their dependency constraint from whatever it was, to ^x.y.0 where x.y is the most recent published major and minor release of that package, *except* that for @rollup/plugin-terser, ^0.1.0 is used instead of ^0.2.0 due to a catastrophic bug in v0.2.0 (exactly) for which there is not yet a fix: rollup/plugins#1366 This fixes a dependency conflict reported by “npm install”: npm ERR! While resolving: markdown-it-dollarmath@0.4.2 npm ERR! Found: eslint-plugin-promise@6.1.1 npm ERR! node_modules/eslint-plugin-promise npm ERR! dev eslint-plugin-promise@"^6.0.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer eslint-plugin-promise@"^4.2.1 || ^5.0.0" npm ERR! from eslint-config-standard@16.0.3 npm ERR! node_modules/eslint-config-standard npm ERR! dev eslint-config-standard@"^16.0.3" from the root project I believe the update that was actually _required_ to fix this was eslint-config-standard 16.x -> 17.x, but it is easiest to update everything at once. For the peer dependency on markdown-it, change from ^12.3.2 to “12 - 13” as there do not appear to have been any API changes in that range that would break this plugin. These updates required a handful of minor code changes: - Rename rollup.config.js to rollup.config.mjs so it is parsed as an ES module. - Annotate all bundler outputs with ‘exports: "named"’ to squelch a new warning (the default export is only for the sake of Jest, so the issue described at https://rollupjs.org/guide/en/#outputexports should not be relevant to us). - The ceremony for importing the terser plugin has changed. - The ceremony for getting at katex.renderToString has changed. With these changes applied, “npm run lint”, “npm run test”, and “npm run build” all succeed.
This avoids the __filename error for me, but now I get the error:
I may have some other issues present, but this doesn't clarify too much for me. |
Thanks. It appears in my case that the config is instead a |
Got a fix available for this under #1374?, can I get a review from a code owner? |
Correct, copied the wrong PR nr. Fixed. |
I think collaboration on the original PR fix would have been a better route to go. @tada5hi will have to weigh in. |
@shellscape I can confirm that using I also updated my pr, but im totally fine merging the pr (#1374) of @jonkoops. |
Works for me either way, whatever is your preference 👍 |
For me, this allows it to run, but throws a
|
I'm guessing it's because it sets import { fileURLToPath } from 'url'
Object.defineProperty(global, '__filename', {
get() { return fileURLToPath(import.meta.url) },
}) |
This gives the same value every time because |
What you really want is: import { fileURLToPath } from 'url';
// @todo: Delete the stuff below once the issue is resolved.
// @see https://github.com/rollup/plugins/issues/1366
const errorStackMatchFileUrlRegexp = /^.+?\((.+?):\d+:\d+\)$/;
Object.defineProperty(global, '__filename', {
get: () => fileURLToPath(
// Get the callee from the stack.
// - [0]: always the `'Error'` string;
// - [1]: always the current file;
// - [2]: always the file where the `__filename` global has been accessed.
// 'Error',
// ' at get (file:///path/to/rollup.config.mjs:13:7)',
// ' at terser (file:///path/to/node_modules/@rollup/plugin-terser/dist/es/index.js:121:19)',
new Error()
.stack
.split('\n')
.at(2)
.replace(errorStackMatchFileUrlRegexp, '$1'),
),
}); |
@shellscape do you think we can merge one of the pull requests? If the problem with the source-map should still be a problem, i would like to address that in another pr, if you are fine with that. |
Am I missing something in this thread? Why would this plugin pollute the ESM global scope with a variable it does not need? The solution isn't to polyfill the |
@jonkoops i totally agree and I would also like to release the fix as soon as possible. |
We don't just merge to merge. We can always revert a change while a proper fix is debated and produced. opening a separate PR was a bad move because it's splintered discussion. Both PRs have unresolved discussions, and until the community and @tada5hi coalesce around one solution I'm not comfortable moving forward with either. |
@shellscape you are completly right and that should definitly not be the case. I'm sorry 😔 , I forgot to mark the dicussion in #1367 as closed. |
Sorry, but hard disagree, my solution was different at the time it was created. In fact, no discussion has take place on my PR so I fail to see this argument. Aside from that @tada5hi's PR now has pretty much the same implementation. I don't feel like discussing this further, as it is quite an unproductive thing to keep talking about it. Let me make this very easy by closing my PR, so we can work on resolving the issue under @tada5hi's PR instead. |
Yep. I checked in the beginning, if the
I got your point. I do, however, fully understand @shellscape's concerns and i prefer his approach. |
Naturally I agree with what @shellscape is saying about that PRs need to have to be properly discussed. I think that we've pretty much come to the same conclusion on what the preferred solution is at this point.
Ah, yeah I can see where the confusion comes from there. FYI I left a couple of comments on your PR, but implementation-wise things look good to me 👍 |
fyi v0.2.1 is working for my esm packages. |
Very nice, thanks for the effort all! |
Replace the deprecated rollup-plugin-terser with @rollup/plugin-terser. Then, for all packages in devDependencies, update their dependency constraint from whatever it was, to ^x.y.0 where x.y is the most recent published major and minor release of that package, *except* that for @rollup/plugin-terser, ^0.1.0 is used instead of ^0.2.0 due to a catastrophic bug in v0.2.0 (exactly) for which there is not yet a fix: rollup/plugins#1366 This fixes a dependency conflict reported by “npm install”: npm ERR! While resolving: markdown-it-dollarmath@0.4.2 npm ERR! Found: eslint-plugin-promise@6.1.1 npm ERR! node_modules/eslint-plugin-promise npm ERR! dev eslint-plugin-promise@"^6.0.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer eslint-plugin-promise@"^4.2.1 || ^5.0.0" npm ERR! from eslint-config-standard@16.0.3 npm ERR! node_modules/eslint-config-standard npm ERR! dev eslint-config-standard@"^16.0.3" from the root project I believe the update that was actually _required_ to fix this was eslint-config-standard 16.x -> 17.x, but it is easiest to update everything at once. For the peer dependency on markdown-it, change from ^12.3.2 to “12 - 13” as there do not appear to have been any API changes in that range that would break this plugin. These updates required a handful of minor code changes: - Rename rollup.config.js to rollup.config.mjs so it is parsed as an ES module. - Annotate all bundler outputs with ‘exports: "named"’ to squelch a new warning (the default export is only for the sake of Jest, so the issue described at https://rollupjs.org/guide/en/#outputexports should not be relevant to us). - The ceremony for importing the terser plugin has changed. - The ceremony for getting at katex.renderToString has changed. With these changes applied, “npm run lint”, “npm run test”, and “npm run build” all succeed.
Error:
Should use
import.meta.url
instead.The text was updated successfully, but these errors were encountered: