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

require('rollup/dist/loadConfigFile') causes unexpected ESM-related error #4460

Closed
Krinkle opened this issue Apr 10, 2022 · 3 comments · Fixed by #4483
Closed

require('rollup/dist/loadConfigFile') causes unexpected ESM-related error #4460

Krinkle opened this issue Apr 10, 2022 · 3 comments · Fixed by #4483

Comments

@Krinkle
Copy link

Krinkle commented Apr 10, 2022

Rollup Version

2.70.1

Operating System (or Browser)

Linux

Node Version (if applicable)

v14.17.5

Link To Reproduction

N/A

Expected Behaviour

In our project we build a watch mode in which we run node build/watch.js and in there run const loadConfigFile = require('rollup/dist/loadConfigFile'); among other things. This has worked for years, and while the convention in ESM code is to include an extension, in CJS it tends to have been omitted.

Actual Behaviour

In the last release, this seems to have stopped working. We now get an ESM error.. from a CJS import in a CJS file.

Uncaught Error: Cannot find module '/qunit/node_modules/rollup/dist/loadConfigFile'
    at createEsmNotFoundErr (internal/modules/cjs/loader.js:916:15)
    at finalizeEsmResolution (internal/modules/cjs/loader.js:909:15)
    at resolveExports (internal/modules/cjs/loader.js:449:14)
    at Function.Module._findPath (internal/modules/cjs/loader.js:489:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:875:27)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18) 

I've not included a test case as I believe this issue is already understood and discussed at #4436 and #4443. However that's quite burried and I'm hoping this will help others to find the issue quicker and avoid further duplicate reports.

The short-term workaround is to include .js in your require statement, or pin to an older version of Rollup.

@@ input @@
- const loadConfigFile = require('rollup/dist/loadConfigFile');
+ const loadConfigFile = require('rollup/dist/loadConfigFile.js');

@@ output @@
- Uncaught Error: Cannot find module '/qunit/node_modules/rollup/dist/loadConfigFile'
+ [AsyncFunction: loadAndParseConfigFile]
Krinkle added a commit to qunitjs/qunit that referenced this issue Apr 10, 2022
After updating from rollup 2.56.3 to 2.70.1, this broke because
upstream maps the extension-less variant to ESM. This will hopefully
be fixed soon, but is easy enough to workaround in the interim.

Workaround upstream rollup/rollup#4460.
@lukastaegert
Copy link
Member

Thanks your for the issue. I fear we will need to leave it as such (i.e. you need to add the extension) until the next major version (and may be beyond that?) because that is the only way to maintain compatibility with latest Node, there have been many discussions and previously we were using a deprecated exports pattern that is no longer supported in latest Node.

@lukastaegert
Copy link
Member

Actually as I just saw this is the only "public" API we have in dist, I think I can add an exception

@lukastaegert
Copy link
Member

#4483 should solve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants