0

I tried to use pixi.js and use angular universal to build the project, but it seems to be unsuccessful.

error message:

'can only be default-imported using the 'allowSyntheticDefaultImports' flag
    
    3 import EventEmitter from 'eventemitter3';
             ~~~~~~~~~~~~
    
      node_modules/@pixi/utils/node_modules/eventemitter3/index.d.ts:64:1
        64 export = EventEmitter;
           ~~~~~~~~~~~~~~~~~~~~~~
        This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

No solution has been found so far. Is it possible to skip pixi.js during the universal building process?

component.ts:

import { Application } from 'pixi.js';

@Component({
  selector: 'app-main',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss']
})
public app: Application;
export class MainComponent implements OnInit {
  this.app = new Application({});
}

Below is my package.json:

{
      "private": true,
      "dependencies": {
        "@angular/animations": "~9.1.0",
        "@angular/cdk": "^9.2.2",
        "@angular/common": "~9.1.0",
        "@angular/compiler": "~9.1.0",
        "@angular/core": "~9.1.0",
        "@angular/forms": "~9.1.0",
        "@angular/material": "^9.2.2",
        "@angular/platform-browser": "~9.1.0",
        "@angular/platform-browser-dynamic": "~9.1.0",
        "@angular/platform-server": "~9.1.0",
        "@angular/router": "~9.1.0",
        "@nguniversal/express-engine": "^9.1.0",
        "@tinymce/tinymce-angular": "^3.6.0",
        "@types/pixi.js": "^5.0.0",
        "express": "^4.15.2",
        "file-saver": "^2.0.2",
        "moment": "^2.24.0",
        "ngx-cookie-service": "^3.0.4",
        "ngx-material-file-input": "^2.1.1",
        "pixi.js": "^6.1.3",
        "rxjs": "~6.5.4",
        "tslib": "^1.10.0",
        "zone.js": "~0.10.2"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.901.0",
        "@angular/cli": "~9.1.0",
        "@angular/compiler-cli": "~9.1.0",
        "@angular/language-service": "~9.1.0",
        "@nguniversal/builders": "^9.1.0",
        "@types/express": "^4.17.0",
        "@types/file-saver": "^2.0.1",
        "@types/jasmine": "~3.5.0",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "^12.11.1",
        "codelyzer": "^5.1.2",
        "jasmine-core": "~3.5.0",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~4.4.1",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage-istanbul-reporter": "~2.1.0",
        "karma-jasmine": "~3.0.1",
        "karma-jasmine-html-reporter": "^1.4.2",
        "protractor": "~5.4.3",
        "ts-node": "~8.3.0",
        "tslint": "~6.1.0",
        "typescript": "~3.8.3"
      }
    }

UPDATE:

I tried one of the methods in this answer, changing tsconfig.json:

"angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "esModuleInterop": true, <----------------------------add this
    "allowSyntheticDefaultImports": true <----------------------------and this
  },

But the error message still encountered when packaging to the universal stage.

Error message:

ERROR in server.ts:14:18 - error TS2349: This expression is not callable.
  Type 'typeof e' has no call signatures.

14   const server = express();
                    ~~~~~~~

  server.ts:4:1
    4 import * as express from 'express';
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

I try to set only "allowSyntheticDefaultImports": true, it may be packaged successfully, but there are a lot of errors in the log during operation:

Node.js log error message:

.
.
eldset":case"figcaption":case"figure":case"footer":case"header":case"hgroup":case"listing":case"main":case"menu":case"nav":case"ol":case"pre":case"section":case"summary":case"ul":if(!stack.inScope(value))return;return stack.generateImpliedEndTags(),void stack.popTag(value);case"form":if(stack.contains("template")){if(!stack.inScope("form"))return;stack.generateImpliedEndTags(),stack.popTag("form")}else{var openform=form_element_pointer;if(form_element_pointer=null,!openform||!stack.el....
.
.

ReferenceError: self is not defined
.
.
.
Finn
  • 1,323
  • 5
  • 24
  • 46
  • 1
    I already faced this issue by using an external js library with his typescript definition. I solved it by updating my tsconfig file like described here: https://stackoverflow.com/questions/60935889/cant-do-a-default-import-in-angular-9/65402895. Could you please try and keep us posted ? – JStw Oct 20 '21 at 04:29
  • @Finn shouldnt this import look like this? : `import express from 'express';` . If that doesnt help then you should show more source code (where you get the error - so where you do that import etc) or create a minimal reproduction of this problem in some new repo - which someone can run and check. Also i would suggest asking on Pixi.js github repo (but please have that reproduction example ready to show). – domis86 Oct 21 '21 at 09:26
  • @domis86 pixi.js can work normally in the development mode. I have a problem when packaging the `universal` process, which is more related to the angular , so I did not ask on the github of pixi.js. – Finn Oct 22 '21 at 06:28
  • @domis86 `import * as express from 'express'; `<<< angular `universal` will operate through `nodejs` `express`, which is the default in the server.ts file by Angular. – Finn Oct 22 '21 at 06:46
  • Try setting `"target"` option to `"es5"`, or try some combinations of settings from working examples like: https://github.com/pixijs/pixijs/issues/7685#issuecomment-895369301 or https://github.com/pixijs/pixijs/issues/6045#issuecomment-525499387 – domis86 Oct 27 '21 at 22:16

0 Answers0