I have an Angular application where I'm trying to import a JS file with a constructor. But when I run the application, webpack throws an error.
Javascript files in assets:
TestServiceClient = function(arg1, arg2) { }; module.exports = TestServiceClient; module.exports.default = TestServiceClient;
Import in Angular:
var TestServiceClient = require('../assets/test'); @Injectable() export class ServiceTest { constructor() { const svc = new TestServiceClient('testarg1', 'testarg2'); } }
This is the error I get:
Uncaught ReferenceError: TestServiceClient is not defined at 3472 (test.js:1:18) at __webpack_require__ (bootstrap:19:1)
Can you help me find the problem?
P粉6158297422024-04-05 10:24:09
I have to export it this way:
exports.TestServiceClient = function(arg1, arg2) { };