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

Unable to use import / require file in craco.config.js from src folder in create react app #282

Closed
ARKKYN opened this issue Apr 26, 2021 · 7 comments

Comments

@ARKKYN
Copy link

ARKKYN commented Apr 26, 2021

SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (/Users/ak/office/evenheathcare/dashboard-app/craco.config.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
(Use node --trace-warnings ... to show where the warning was created)
(node:87435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:87435) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@tannerhallman
Copy link

make sure the config is in your root.

@viktor-ulyankin
Copy link

With type: "module" in packege.json:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/z19460316/Documents/work/projects/cce/frontend/frontend/craco.config.js

@atomless
Copy link

atomless commented Nov 1, 2021

With Webpack 5, es6 modules are supported but it looks like craco does not support this?

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).

@FloMaetschke
Copy link

same problem

@israx
Copy link

israx commented Dec 21, 2021

The same problem

@rafaelboschini
Copy link

same here

@dilanx
Copy link
Owner

dilanx commented Jun 15, 2022

This issue will now be tracked by #429

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

8 participants