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

TypeError: Cannot read properties of undefined (reading 'then') when using ESM to export config #3684

Closed
palapapa opened this issue Mar 19, 2023 · 2 comments · Fixed by #3685

Comments

@palapapa
Copy link

Bug report

What is the current behavior?
Running npx webpack --config config/webpack.config.js gives this error:

[webpack-cli] TypeError: Cannot read properties of undefined (reading 'then')
    at WebpackCLI.isPromise (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:27:29)
    at loadConfigByPath (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:1354:26)
    at async Promise.all (index 0)
    at async WebpackCLI.loadConfig (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:1375:35)
    at async WebpackCLI.createCompiler (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:1643:22)
    at async WebpackCLI.runWebpack (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:1738:20)
    at async Command.<anonymous> (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:885:21)
    at async Command.parseAsync (C:\JavaScript\wiki-translator\node_modules\webpack-cli\node_modules\commander\lib\command.js:935:5)
    at async Command.<anonymous> (C:\JavaScript\wiki-translator\node_modules\webpack-cli\lib\webpack-cli.js:1292:13)
    at async Command.parseAsync (C:\JavaScript\wiki-translator\node_modules\webpack-cli\node_modules\commander\lib\command.js:935:5)

webpack.config.js:

export let config =
{
    "entry": "dist/popup.js"
}

dist/popup.js:

"use strict";
console.log("Hello World!");

package.json:

{
    "name": "wiki-translator",
    "version": "0.1.0",
    "description": "A Chrome extension that automatically detects the longest language of a Wikipedia atricle and translates it.",
    "private": true,
    "scripts":
    {
        "watch": "tsc-watch --project config/tsconfig.json --onSuccess \"webpack --mode=development --config config/webpack.config.js\"",
        "build": "tsc --project config/tsconfig.json; webpack --mode=production --config config/webpack.config.js"
    },
    "devDependencies":
    {
        "@types/chrome": "^0.0.181",
        "copy-webpack-plugin": "^10.2.4",
        "css-loader": "^6.7.3",
        "file-loader": "^6.2.0",
        "mini-css-extract-plugin": "^2.7.5",
        "prettier": "^2.8.4",
        "ts-loader": "^9.2.8",
        "tsc-watch": "^6.0.0",
        "typescript": "^4.6.3",
        "webpack": "^5.76.2",
        "webpack-cli": "^5.0.1",
        "webpack-merge": "^5.8.0"
    },
    "type": "module"
}

If the current behavior is a bug, please provide the steps to reproduce.
Run npx webpack --config config/webpack.config.js in this repo:
wiki-translator.zip

What is the expected behavior?
Webpack should run successfully.

Other relevant information:
webpack version: 5.76.2
webpack-cli version: 5.0.1
Node.js version: 18.15.0
Operating System: Windows 10 10.0.19044

@palapapa palapapa changed the title [webpack-cli] TypeError: Cannot read properties of undefined (reading 'then') TypeError: Cannot read properties of undefined (reading 'then') when using ESM to export config Mar 19, 2023
@palapapa palapapa changed the title TypeError: Cannot read properties of undefined (reading 'then') when using ESM to export config TypeError: Cannot read properties of undefined (reading 'then') when using ESM to export config Mar 19, 2023
@alexander-akait alexander-akait transferred this issue from webpack/webpack Mar 19, 2023
@alexander-akait
Copy link
Member

We support only default export, please use:

export default
{
    "entry": "dist/popup.js"
}

@alexander-akait
Copy link
Member

We don't know what is config named export so we don't support named exports

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

Successfully merging a pull request may close this issue.

2 participants