Can't run the app because 'experiment is not enabled'

Hello community,

I am a very beginner in Forge and JS, trying to run my app but can’t do because of that error:

File was processed with these loaders:
 * ../tunnel/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
    at /tunnel/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js:54:11
    at Hook.eval [as call] (eval at create (/tunnel/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
    at Hook.CALL_DELEGATE [as _call] (/tunnel/node_modules/tapable/lib/Hook.js:14:14)
    at JavascriptParser.walkAwaitExpression (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:2314:29)
    at JavascriptParser.walkExpression (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:2244:10)
    at JavascriptParser.walkVariableDeclaration (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:2098:33)
    at JavascriptParser.walkStatement (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:1592:10)
    at JavascriptParser.walkStatements (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:1453:9)
    at JavascriptParser.parse (/tunnel/node_modules/webpack/lib/javascript/JavascriptParser.js:3338:9)
    at /tunnel/node_modules/webpack/lib/NormalModule.js:1080:26
    at processResult (/tunnel/node_modules/webpack/lib/NormalModule.js:793:11)
    at /tunnel/node_modules/webpack/lib/NormalModule.js:853:5
    at /tunnel/node_modules/loader-runner/lib/LoaderRunner.js:406:3
    at iterateNormalLoaders (/tunnel/node_modules/loader-runner/lib/LoaderRunner.js:232:10)
    at iterateNormalLoaders (/tunnel/node_modules/loader-runner/lib/LoaderRunner.js:239:10)
    at /tunnel/node_modules/loader-runner/lib/LoaderRunner.js:254:3

On SO I found it’s needed to put this excerpt to webpack.config.js file

experiments: {
  topLevelAwait: true
}

However, I can’t find this file.

What to do to make the app running?

1 Like

facing the same problem here

You are probably using await outside of a function scope, try adding inside it.

Remember if wait goes inside of the function, this function has to be async.

2 Likes