Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

377
Views
`experiments.topLevelAwait: true` inesperadamente no funciona - ReactJS todavía arroja un error

Tengo el siguiente archivo index.js ,

 import { DataStore } from "aws-amplify"; import { Todo } from "./models"; import React from "react"; import ReactDOM from "react-dom/client"; import "./index.css"; import App from "./App"; import reportWebVitals from "./reportWebVitals"; import Amplify from "aws-amplify"; import awsconfig from "./aws-exports"; Amplify.configure(awsconfig); await new DataStore.save( new Todo({ name: "Lorem ipsum dolor sit amet", description: "Lorem ipsum dolor sit amet", }) ); const root = ReactDOM.createRoot(document.getElementById("root")); root.render( <React.StrictMode> <App /> </React.StrictMode> ); reportWebVitals();

Debido al fragmento de código de await , recibo el siguiente error cuando ejecuto npm run start ,

 Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it) at /home/saif/Projects/myapp/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js:54:11 at Hook.eval [as call] (eval at create (/home/saif/Projects/myapp/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16) at Hook.CALL_DELEGATE [as _call] (/home/saif/Projects/myapp/node_modules/tapable/lib/Hook.js:14:14) at JavascriptParser.walkAwaitExpression (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:2320:29) at JavascriptParser.walkExpression (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:2250:10) at JavascriptParser.walkExpressionStatement (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:1638:8) at JavascriptParser.walkStatement (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:1565:10) at JavascriptParser.walkStatements (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:1459:9) at JavascriptParser.parse (/home/saif/Projects/myapp/node_modules/webpack/lib/javascript/JavascriptParser.js:3353:9) at /home/saif/Projects/myapp/node_modules/webpack/lib/NormalModule.js:1087:26

Parece bastante fácil de entender, así que creo un archivo webpack.config.js en el directorio raíz al mismo nivel que el project.json , y lleno el contenido con él,

 module.exports = { experiments: { topLevelAwait: true, }, };

Aún tengo el error. ¿Se supone que debo poner esto en otro lugar?

Por contexto, estas son mis versiones,

 ❯ node --version v17.9.0 ❯ npm --version 8.5.5

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como sé, actualmente no hay soporte de espera de nivel superior en reaccionar, intente de esta manera.

 (async () => { await new DataStore.save( new Todo({ name: "Lorem ipsum dolor sit amet", description: "Lorem ipsum dolor sit amet", }) ) })()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!