autoInjectable not working in Chrome Extension using Webpack
See original GitHub issueDescribe the bug TSyringe seems not to be working when used in a Chrome Extension using Webpack and ts-loader.
To Reproduce
// Database.ts
class Database {
constructor() {}
}
export default Database;
// ConfigService.ts
import "reflect-metadata";
import { autoInjectable } from "tsyringe";
import Database from "../Database";
@autoInjectable()
class ConfigService {
constructor(private db?: Database) {}
}
export default ConfigService;
// Background.ts
import "reflect-metadata";
import { container } from "tsyringe";
import Database from "../db/Database";
import ConfigService from "../db/services/ConfigService";
container.register<Database>(Database, { useClass: Database });
const service = new ConfigService();
Expected behavior
Expected new ConfigService()
to return a ConfigService instance with dependencies resolved automatically.
Actual behavior
new ConfigService()
throws an uncaught TypeError Class constructor ConfigService cannot be invoked without ‘new’
Version: 4.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11
Top Results From Across the Web
WebPack + WebExtensions/Chrome Extension - Stack Overflow
The best way to work around this is using the extension API's message system, with the sendMessage function and onMessage event - or...
Read more >Does Chrome Extensions Allow Webpack Bundle in ...
Hi, I'm writing an extension using React Typescript and webpack, ... 1) WebStore requires you to use minification but not obfuscation.
Read more >chrome-extension-boilerplate-react - npm
A chrome extension boilerplate built with React 17, Webpack 5, and Webpack Dev Server 4. Latest version: 4.4.0, last published: a month ago....
Read more >How to Build a Chrome Extension With React, TypeScript, and ...
And then I thought, “Why isn't there something like Create React App for Chrome extensions - run one command and get everything up...
Read more >Creating a Chrome Extension with React and TypeScript
Similar to web pages, Chrome extensions are created with HTML, JavaScript and ... project using Webpack, which create-react-app is based on.
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
It looks like webpack is prefering the
"module": "./dist/esm5/index.js"
config in thetsyringe/package.json
over the better option"es2015": "./dist/esm2015/index.js"
. The esm5 does not use theclass
keyword and that’s why you’re getting this error. To fix it, I added the following config in mywebpack.config.js
file:Not to resurrect this, but is there any way that this could be solved by the repository rather than by each user? Same issue today when running webpack but packing files for a Node runtime and using
esbuild-loader
. Why does it resolve toesm5
when our targets are higher?