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

Error when using import statement #209

Closed
2 of 6 tasks
dmtri310 opened this issue Mar 9, 2022 · 1 comment
Closed
2 of 6 tasks

Error when using import statement #209

dmtri310 opened this issue Mar 9, 2022 · 1 comment
Labels

Comments

@dmtri310
Copy link

dmtri310 commented Mar 9, 2022

Type:

  • bug
  • feature
  • enhancement
  • question

Environment:

  • OS: Arch Linux
  • Browser: Firefox (98.0)
  • Library Version: 1.1.9

I'm going to open a PR:

  • yes
  • no

Description:
Hello! I have a webpack config in typescript (webpack.config.ts) and I get This expression is not constructable error when I use import statement (instead of require)

import ExtReloader from 'webpack-ext-reloader'
import { Configuration } from 'webpack'

const config: Configuration = {
//...
plugins: [
    new ExtReloader(), 
    // ERROR: This expression is not constructable.
    // Type 'typeof import("/home/brose514/Projects/dmtri310/webextension-vue-ts-template/node_modules/webpack-ext-reloader/typings/webpack-ext-reloader")' has no construct signatures.ts(2351)
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "sourceMap": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "ts-node": {
    "compilerOptions": {
      "module": "commonjs"
    }
  }
}

webpack.config.ts

import HtmlWebpackPlugin from 'html-webpack-plugin'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import ExtReloader from 'webpack-ext-reloader'
import { VueLoaderPlugin } from 'vue-loader'
import { Configuration } from 'webpack'
import { resolve } from 'path'

const config: Configuration = {
  entry: {
    content: resolve(__dirname, 'src/content.ts'),
    background: resolve(__dirname, 'src/background.ts'),
    popup: resolve(__dirname, 'src/popup/index.ts'),
    options: resolve(__dirname, 'src/options/index.ts'),
  },
  output: {
    path: resolve(__dirname, 'dist'),
    filename: '[name].js',
    clean: true,
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'esbuild-loader',
        options: {
          loader: 'ts',
          target: 'es2015',
        },
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          enableTsInTemplate: true,
        },
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  plugins: [
    new ExtReloader(),
    new VueLoaderPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: resolve(
            __dirname,
            'node_modules/webextension-polyfill/dist/browser-polyfill.js',
          ),
        },
        { from: resolve(__dirname, 'src/static') },
      ],
    }),
    new HtmlWebpackPlugin({
      filename: 'popup.html',
      inject: false,
      templateParameters: {
        js: 'popup.js',
      },
    }),
    new HtmlWebpackPlugin({
      filename: 'config.html',
      inject: false,
      templateParameters: {
        js: 'config.js',
      },
    }),
  ],
}

export default config
@MxtOUT
Copy link

MxtOUT commented Mar 16, 2023

Same here, if you look at the type definitions you'll see that only types and interfaces are exported, nothing you can construct directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants