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

Don't support config in a ts type webpack config file? #31

Closed
HduSy opened this issue Aug 11, 2024 · 4 comments
Closed

Don't support config in a ts type webpack config file? #31

HduSy opened this issue Aug 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@HduSy
Copy link

HduSy commented Aug 11, 2024

Describe the bug

when i config the plugin in my "webpak.dev.ts" file, terminal report this error:
[webpack-cli] Failed to load '/xxx/svg-chunk-webpack-plugin/example/webpack.config.ts' config [webpack-cli] TypeError: Unknown file extension ".ts" for /xxx/svg-chunk-webpack-plugin/example/webpack.config.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9) at defaultGetFormat (node:internal/modules/esm/get_format:203:36) at defaultLoad (node:internal/modules/esm/load:143:22) at async ModuleLoader.load (node:internal/modules/esm/loader:403:7) at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:45) at async link (node:internal/modules/esm/module_job:78:21) { code: 'ERR_UNKNOWN_FILE_EXTENSION' }

Steps to reproduce

try edit this project's example, will reproduce

Expected behavior

support config it in a ts type webpack config file

Screenshots and recordings

No response

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 186.59 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 8.14.3 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 127.0.6533.100
    Safari: 17.5

Severity

Annoyance

@HduSy HduSy added the bug Something isn't working label Aug 11, 2024
@mariusGundersen
Copy link

It seems like webpack.config.ts can't import esm files, only cjs files. So there needs to be some transpiled files that use the old fashioned module.exports = syntax.

@mariusGundersen
Copy link

This might be the simplest way to make it export both esm and cjs: https://thesametech.com/how-to-build-typescript-project/

@mariusGundersen
Copy link

mariusGundersen commented Aug 23, 2024

After trying to make it work I have given up and found a workaround:

  • in tsconfig.json you need to make sure you have "module": "NodeNext" and "moduleResolution": "NodeNext", probably inside the "ts-node" section.
  • Then you do const SvgChunkWebpackPlugin = await import('svg-chunk-webpack-plugin'); inside the default exported function.

In other words, this doesn't need to be fixed here

@yoriiis
Copy link
Owner

yoriiis commented Aug 26, 2024

Thanks @mariusGundersen for the investigations!

Even though I haven't managed to get a configuration with ESM and TS running locally, it's not a subject related to this project. There are several issues on this subject:

I'm going to close this issue as there is no link with the plugin imo. Thanks.

@yoriiis yoriiis closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants