Error with TypeScript config and ESM
See original GitHub issueBug description
I’m using TypeScript webpack config, running with ts-node/esm loader It yells at me:
[webpack-cli] file:///Users/cyber/dev/tombo/freezy/src/webpack/webpack.common.ts:6
import { ESBuildMinifyPlugin } from "esbuild-loader";
^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'ESBuildMinifyPlugin' not found. The requested module 'esbuild-loader' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'esbuild-loader';
const { ESBuildMinifyPlugin } = pkg;
If I do
import pkg from 'esbuild-loader';
const { ESBuildMinifyPlugin } = pkg;
Then I get the error:
[webpack-cli] Failed to load '/Users/cyber/dev/tombo/freezy/src/webpack/webpack.prod.ts' config
[webpack-cli] src/webpack/webpack.common.ts:7:9 - error TS2339: Property 'ESBuildMinifyPlugin' does not exist on type '(this: any, source: string) => Promise<void>'.
7 const { ESBuildMinifyPlugin } = pkg;
~~~~~~~~~~~~~~~~~~~
Reproduction
import pkg from 'esbuild-loader';
const { ESBuildMinifyPlugin } = pkg;
Node.js package manager
npm
Environment
System:
OS: macOS 12.0.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 25.19 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.5 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.2.0 - /usr/local/bin/npm
npmPackages:
esbuild-loader: ^2.17.0 => 2.17.0
webpack: ^5.65.0 => 5.65.0
### Can you contribute a fix?
- [X] I’m interested in opening a pull request for this issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Documentation - ECMAScript Modules in Node.js - TypeScript
This setting controls whether .js files are interpreted as ES modules or CommonJS modules, and defaults to CommonJS when not set. When a...
Read more >TypeScript and native ESM on Node.js - 2ality
In this blog post, I'll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.
Read more >TypeScript config can't resolve custom paths with ESM enabled
I've been trying to crack this thing down for quite a while now, I want my tsconfig.json paths to be resolved when ESM...
Read more >tsc-esm-fix - npm
Nightly build TypeScript 4.7 provides experimental esm support. ... src/main/ts/q/u/x/index.ts:1:21 - error TS2835: Relative import paths ...
Read more >TypeScript - webpack
Let's set up a configuration to support JSX and compile TypeScript down to ES5. ... true and "esModuleInterop" : true in your tsconfig.json...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! Just wanted to mention that we faced a related issue with Nuxt3 as all internals are ESM only. (without typescript also having issues)
A simple workaround: (https://github.com/nuxt/framework/pull/2460)
Does setting esModuleInterop in tsconfig.json help?
In any case, happy to add an ESM distribution now that TS is starting to support export maps in 4.6.0