【发布时间】:2019-09-27 12:57:03
【问题描述】:
我正在使用 Electorn 和 angular 8 构建桌面应用程序。我正在尝试在 index.html 中导入一个 javascript 文件,其内容如下。
import ipcRenderer from 'electron';
import {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} from 'electron-push-receiver/src/constants';
所以当我使用上面的代码时,我得到错误Uncaught SyntaxError: Unexpected identifier。
当我使用以下代码时,我得到Uncaught ReferenceError: require is not defined
const { ipcRenderer } = require ('electron')
const {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} = require ('electron-push-receiver/src/constants')
有什么解决办法?
所有角度导入都适用于上面的第一个 sn-ps。他们没有require。所以我假设第一个 sn-p 应该在我以角度导入它时工作。
我通过在 angular.json 文件中指定以下内容来导入文件。
"scripts": [
"../path/to/.js",
]
【问题讨论】:
-
import适用于 ES6 模块。您是否将应用程序的脚本标记类型设置为模块,如下所示:<script type="module" src="...">?还是 Angular 会自动为您做到这一点?没有这个,导入将不起作用。来源:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… -
您是否为
import获得了Unexpected identifier?require是特定于节点的,如果您使用的是 requirejs 模块 laoder。 -
angular 可能会自动进行@user95227,因为
ts文件中的其他导入工作。 -
@ambianBeing 当我使用 import 我得到
Unexpected Identifier但我不确定哪个确切的标识符是。 -
意外的标识符可能是
import
标签: javascript angular ecmascript-6 electron