相关疑难解决方法(0)

Angular:7.2.1 ES6 类 ReferenceError:初始化前无法访问“X”

我有以下 TypeScript 类

export class Vehicule extends TrackableEntity {
  vehiculeId: number;
  constructor() {
    super();
    return super.proxify(this);
  }
}
Run Code Online (Sandbox Code Playgroud)

我在 tsconfig.json 中的打字稿目标配置为 es6:

"compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
}
Run Code Online (Sandbox Code Playgroud)

在运行时,在 Chrome 中,代码失败:

ReferenceError: Cannot access 'Vehicule' before initialization
    at Module.Vehicule (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:10559:100)
    at Module../src/app/domain/models/VehiculeGpsBoxInfo.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:11156:69)
    at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
    at Module../src/app/domain/models/Vehicule.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:10571:78)
    at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
    at Module../src/app/components/dispositifsDATI/mainDATI/listDATI/listDATI.component.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:6447:82)
    at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
    at Module../src/app/components/dispositifsDATI/index.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:3053:95)
    at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
    at Module../src/app/components/dispositifsDATI/dispositifsDATI.routes.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:2982:64)
Run Code Online (Sandbox Code Playgroud)

我需要将 es5 更改为 es6 以解决另一个问题 …

javascript typescript webpack es6-class angular

34
推荐指数
5
解决办法
6万
查看次数

参考错误:初始化前无法访问“播放器”

所以我一直在使用 ES6 风格的语法在 Nodejs 上使用 ESM 模块加载器进行导入/导出。一切都很好,直到我开始收到与导入有关的错误。

以下是错误消息:

joseph@InsaneMachine:~/placeholder2/main-server$ npm start

> main-server@1.0.0 start /home/joseph/placeholder2/main-server
> nodemon --experimental-modules src/index.mjs

[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --experimental-modules src/index.mjs`
(node:16942) ExperimentalWarning: The ESM module loader is experimental.
file:///home/joseph/placeholder2/main-server/src/games/game-player.mjs:3
export default class GamePlayer extends Player
                                        ^

ReferenceError: Cannot access 'Player' before initialization
    at file:///home/joseph/placeholder2/main-server/src/games/game-player.mjs:3:41
    at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
    at async Loader.import (internal/modules/esm/loader.js:132:24)
[nodemon] app crashed - waiting for file …
Run Code Online (Sandbox Code Playgroud)

javascript node.js es6-modules

17
推荐指数
2
解决办法
4万
查看次数

未捕获的类型错误:没有“new”就不能调用类构造函数平台

我安装了 Angular CDK 以便使用 PrimeNG 的下拉组件,但它会引发错误。

我在 app.module.ts 中添加了这个:

import {DropdownModule} from 'primeng/dropdown';
Run Code Online (Sandbox Code Playgroud)

只需输入以下内容即可安装 Angular CDK:

npm install @angular/cdk --save
Run Code Online (Sandbox Code Playgroud)

angular angular-cdk

6
推荐指数
1
解决办法
8202
查看次数

类型错误:如果没有“new”,则无法调用类构造函数模型

我在一个应用程序中将SequelizeNodeJavaScript一起使用。如您所知,当您执行时,sequelize-init它会创建configmigrationsmodelsseeders文件夹。在models文件夹内,有一个index.js文件(由 cli 生成),它负责从当前文件夹中读取所有模型及其关联:

索引.js

'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const sequelize = require('../database/connection');
const db = {};

fs
  .readdirSync(__dirname)
  .filter(file => {
    return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
  })
  .forEach(file => {
    const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
    db[model.name] = model;
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js sequelize.js ecmascript-6 babeljs

6
推荐指数
1
解决办法
3万
查看次数

Angular 作为 Webpack 外部

我目前正在尝试通过 Webpack 外部对象外部化 Angular 依赖项来缩短构建时间。到目前为止,我已经为 React 和其他小库实现了这一目标。

如果我只是移动 '@angular/compiler' 它也可以工作,但是当外部化 '@angular/core' 和其他人时,我Can't resolve all parameters for ApplicationModule: (?) at at syntaxError (util.ts:100) at CompileMetadataResolver._getDependenciesMetadata (metadata_resolver.ts:957) ...在引导应用程序时收到错误。

我使用的文件是您可以在 unpkg.com 中找到的 8.2.14 UMD 包,我的外部文件是:

[
    /^@example\, 
    /^rxjs$/, 
    /^rxjs\/operators$/, 
    /^@angular\/core$/, 
    /^@angular\/compiler$/, 
    /^@angular\/common$/, 
    /^@angular\/common\/http$/, 
    /^@angular\/forms$/, 
    /^@angular\/platform-browser$/, 
    /^@angular\/platform-browser-dynamic$/, 
    /^@angular\/router$/, 
    /^zone\.js$/,
    /^single-spa$/
]
Run Code Online (Sandbox Code Playgroud)

rxjs 包是在https://cdn.jsdelivr.net/npm/@esm-bundle 中找到的包。

您可以在此 repo 上看到错误:https : //github.com/OriolInvernonLlaneza/test-share-angular

提前致谢!

编辑:多亏了 yurzui 的回答,这个错误得到了解决。但是,我现在收到另一个错误:

Class constructor I cannot be invoked without 'new'
    at new EventEmitter (event_emitter.ts:78)
    at new NgZone (ng_zone.ts:97) …
Run Code Online (Sandbox Code Playgroud)

webpack webpack-externals angular micro-frontend single-spa-angular

5
推荐指数
1
解决办法
1675
查看次数

没有'new' - 使用commonjs的typescript时,不能调用类构造函数

我正在与colyseus(节点游戏服务器框架)进行服务器端聊天.我使用typescript与module:commonjs因为colyseus是建立在commonjs之上的.

我有课程ChatRoom延伸Colyseus.Room.在运行时我收到此错误:

Class constructor Room cannot be invoked without 'new'.
Run Code Online (Sandbox Code Playgroud)

而javascript中的麻烦:

function ChatRoom() {
   return _super !== null && _super.apply(this, arguments) || this;
}
Run Code Online (Sandbox Code Playgroud)

来自typescript类:

import {Room} from "colyseus";

export class ChatRoom extends Room {

    onInit(options) {
        console.log("BasicRoom created!", options);
    }

    onJoin(client) {
        this.broadcast(`${ client.sessionId } joined.`);
    }

    onLeave(client) {
        this.broadcast(`${ client.sessionId } left.`);
    }

    onMessage(client, data) {
        console.log("BasicRoom received message from", client.sessionId, ":", data);
        this.broadcast(`(${ client.sessionId }) ${ data.message }`);
    }

    onDispose() {
        console.log("Dispose BasicRoom"); …
Run Code Online (Sandbox Code Playgroud)

commonjs node.js typescript

2
推荐指数
2
解决办法
4443
查看次数