An error is thrown when importing Javascript prototype constructor in Angular application
P粉916760429
P粉916760429 2024-04-04 11:36:15
0
1
574

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粉916760429
P粉916760429

reply all(1)
P粉615829742

I have to export it this way:

exports.TestServiceClient = function(arg1, arg2) {

};
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template