Closed11

"Cannot destructure property '__extends' of '_tslib_js__WEBPACK_IMPORTED_MODULE_0___..." エラー対応

ピン留めされたアイテム
nbstshnbstsh

まとめ

webpack.config.jsresolve.alias に、tslib: 'tslib/tslib.es6.js' を設定すればOK。

webpack.config.js
module.exports = {
  // ...
  resolve: {
    // ...
    alias: {
      tslib: 'tslib/tslib.es6.js',
    },
  },
nbstshnbstsh

webpack5 で React + TS の project build しようとしたらエラー出た。

Uncaught (in promise) TypeError: Cannot destructure property '__extends' of '_tslib_js__WEBPACK_IMPORTED_MODULE_0___default(...)' as it is undefined.

解決の道のりメモっていく。

nbstshnbstsh

どうやら Radix UI を入れたことが原因っぽいな....

    "@radix-ui/react-select": "^1.1.2",
nbstshnbstsh
nbstshnbstsh

これ関係ありそう

tslib/modules/index.js contains a import tslib from '../tslib.js';
but tslib/tslib.js doesn't contain a default export. It only contains named exports.
Becauses of this tslib is undefined in tslib/modules/index.js.
webpack 4 is unaffected because it doesn't support the exports field.
Node.js is unaffected because it doesn't support the __esModule flag.
But in combination they lead to this error.

https://github.com/webpack/webpack/issues/11613#issuecomment-706170986

nbstshnbstsh

"利用している Library が内部で tslib を使ってて、tslib から default export されているものを import しているが、webpack で bundle するとその default import されているものが undefined になっちゃてる"

みたいな感じなのか....? わからん....

nbstshnbstsh

これも @nuxt/bridge だけどとりあえずみる

https://github.com/nuxt/bridge/issues/25

nbstshnbstsh

いけた!!!

nuxt ではないので、webpack.config.jsresolve.alias を編集。

webpack.config.js
module.exports = {
  // ...
  resolve: {
    // ...
    alias: {
      tslib: 'tslib/tslib.es6.js',
    },
  },
このスクラップは2022/12/02にクローズされました