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

Support ES6 in config #429

Open
dilanx opened this issue Jun 15, 2022 · 5 comments
Open

Support ES6 in config #429

dilanx opened this issue Jun 15, 2022 · 5 comments

Comments

@dilanx
Copy link
Owner

dilanx commented Jun 15, 2022

Unlike Webpack 5, CRACO does not support ES6 modules. Make it so it does.

Error [ERR_REQUIRE_ESM]: require() of ES Module .../craco.config.js from .../node_modules/cosmiconfig/dist/loaders.js not supported.
craco.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename craco.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in .../package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
@thediveo
Copy link

Any news?

@philipvella
Copy link

So you're suggesting playing around with coaco package.json which is installed in the node_modules?

How I wish COACO supports coaco.config.mjs out of the box? 😑

@electriquo
Copy link

if you name craco configuration as craco.config.cjs, does it ease your pain?

@juleshwar
Copy link

I followed this and fixed my issue

  1. Rename craco.config.js to craco.config.cjs
  2. Add this webpack config to craco.config.cjs
module.exports = {
    webpack: {
        configure: {
            module: {
                rules: [
                    {
                        test: /\.m?js$/,
                        resolve: {
                            fullySpecified: false,
                        },
                    },
                ],
            },
        },
    },
};

Got the answer from SO -> https://stackoverflow.com/a/75109686

@dheeraj-jn
Copy link

@dilanx I see both cosmiconfig and cosmiconfig-typescript-loader have added support for ESM in their most recent releases. Would it help upgrading these dependencies?

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

No branches or pull requests

6 participants