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

.proxyrc.js refuses to work with ES6 ("type" = "module") node projects. #7330

Closed
chriseaton opened this issue Nov 19, 2021 · 5 comments · Fixed by #8913
Closed

.proxyrc.js refuses to work with ES6 ("type" = "module") node projects. #7330

chriseaton opened this issue Nov 19, 2021 · 5 comments · Fixed by #8913

Comments

@chriseaton
Copy link

🐛 bug report

When trying to run parcel in a "type": "module" node package, the .proxyrc.js refuses to function, getting treated as common js to a degree. Renaming to .proxyrc.cjs or .proxyrc.mjs appears to be unsupported and are never picked up. This basically makes it impossible to leverage another es6 module in the .proxyrc.js. Attempting to utilize the import(...) function available in modern node causes issues. I attempted to simply change the extension in the Server parcel class to use cjs or mjs but both resulted in some JSON parsing error.

{
"type": "module"
}

none

🤔 Expected Behavior

Support .proxyrc.js in type=module node projects, or alternatively support loading mjs/cjs .proxyrc files.

😯 Current Behavior

Errors on startup when the configuration attempts to load.
When trying to use type module:

TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    at new NodeError (node:internal/errors:371:5)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:39:9)
    at module.exports (/app/.proxyrc.cjs:3:13)
    at Server.applyProxyTable (/app/node_modules/@parcel/reporter-dev-server/lib/Server.js:397:7)
    at async Server.start (/app/node_modules/@parcel/reporter-dev-server/lib/Server.js:421:5)
    at async Object.report (/app/node_modules/@parcel/reporter-dev-server/lib/ServerReporter.js:67:31)
    at async ReporterRunner.report (/app/node_modules/@parcel/core/lib/ReporterRunner.js:105:11)

💁 Possible Solution

Couldn't find a workaround unfortunately, tried all sorts of combinations.

🔦 Context

Trying to use parcel in a module (ES6)-based project.

🌍 Your Environment

Software Version(s)
Parcel 2.0.1
Node v16.13.0
npm/Yarn 8.1.0
Operating System Linux 4.18.0-348.el8.x86_64 x86_64 x86_64 x86_64 GNU/Linux
@mischnic
Copy link
Member

The relevant code:

Search paths for the proxy config

const pkg = await loadConfig(
this.options.inputFS,
fileInRoot,
['.proxyrc.js', '.proxyrc', '.proxyrc.json'],
this.options.projectRoot,
);

Location where the config is then required. (So .mjs would certainly be broken at the moment even after adding it to the list)

let extname = path.extname(configFile).slice(1);
if (extname === 'js') {
let output = {
// $FlowFixMe
config: clone(require(configFile)),

@jaredatron
Copy link

Any update on when this might be fixed?

@Kali95739
Copy link

Yea we need a fix when you can

@jaredatron
Copy link

please add support for .proxyrc.cjs and .proxyrc.mjs

@jaredatron
Copy link

I temporary hacked around this problem by wrapping my parcel commands in a script that dynamically writes a .proxyrc file before calling parcel.

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.

4 participants