An async/await call doesn’t work. I loaded core-js and regenerator-runtime to fix that but it still isn’t working. I’m guessing it’s a matter of the proper components. That’s why I posted my package.json and webpack.config.js files below.
const getPuzzle = async (wordCount) => {
const response = await fetch(`//puzzle.mead.io/puzzle?wordCount=${wordCount}`, {
mode: 'no-cors'
})
if (response.status === 200) {
const data = await response.json()
return data.puzzle
} else {
throw new Error('Unable to get puzzle')
}
}
the error
Uncaught runtime errors:
ERROR
Unable to get puzzle
at _callee$ (http://localhost:8080/scripts/bundle.js:392:17)
at tryCatch (http://localhost:8080/scripts/bundle.js:367:1062)
at Generator.<anonymous> (http://localhost:8080/scripts/bundle.js:367:3008)
at Generator.next (http://localhost:8080/scripts/bundle.js:367:1699)
at asyncGeneratorStep (http://localhost:8080/scripts/bundle.js:368:70)
at _next (http://localhost:8080/scripts/bundle.js:369:163)
package.json:
{
"name": "boilerplate2",
"version": "1.0.0",
"description": "",
"main": "input.js",
"scripts": {
"dev-server": "webpack serve --open --mode development",
"build": "webpack --mode production",
"start": "webpack serve --open --mode development"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.25.6",
"@babel/preset-env": "^7.25.4",
"babel-loader": "^9.2.1",
"core-js": "^3.38.1",
"live-server": "^1.2.0",
"regenerator-runtime": "^0.14.1",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
}
}
webpack.config.js:
const path = require('path')
module.exports = {
entry: ['core-js/stable', 'regenerator-runtime/runtime', './src/index.js'],
output: {
path: path.resolve(__dirname, 'public/scripts'),
filename: 'bundle.js'
},
module: {
rules: [{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
},
devServer: {
static: {
directory: path.resolve(__dirname, 'public')
},
port: 8080,
devMiddleware: {
publicPath: "//localhost:8080/scripts/"
}
},
devtool: 'source-map'
}
Any help is appreciated!