npm安装后找不到导入的库

时间:2019-06-11 09:06:38

标签: node.js npm npm-install node-modules

以下步骤来自:https://github.com/appfeel/node-pushnotifications#installation

我已经安装了软件包:

npm install node-pushnotifications --save
+ node-pushnotifications@1.1.9
updated 1 package and audited 244 packages in 14.663s
found 0 vulnerabilities

使用import PushNotifications from 'node-pushnotifications';

返回错误:

> import PushNotifications from 'node-pushnotifications';
import PushNotifications from 'node-pushnotifications';
       ^^^^^^^^^^^^^^^^^

我不熟悉这种导入库的方法。对于我使用过的所有其他东西(例如表达),导入如下:

var express = require('express');

我错过了一步吗?

如何安装和导入PushNotifications?

3 个答案:

答案 0 :(得分:0)

更改import PushNotifications from 'node-pushnotifications';

var PushNotifications = require('node-pushnotifications')

解决了这个问题。

答案 1 :(得分:0)

Node.JS v10.4.1不支持ES6模块。虽然可以将import语句更改为require,但是如果您想保留import语法,还有其他两个选项也可以使用。

  • 将Node.js升级到Node.js v12-在this版本中,您可以通过在import中添加"type: "module"来启用package.json语法。启动服务器时,您还必须添加--experimental-modules标志。
  • 使用Babel在应用程序中启用import语法。

答案 2 :(得分:-1)

尝试:

  • node-pushnotifications删除package.json
  • 通过npm i node-pushnotifications安装
  • 否则,您可以使用install ny yarn
相关问题