我正在使用ES6语法,并希望在NPM中构建一个小模块,它使用另一个npm模块(例如push-js)作为依赖项。目前,我正在使用rollup来打包和生成我的分发文件。
我不知道在我自己的模块中使用依赖的正确方法是什么。这就是我试过的
import * as Push from 'push.js';
class _MyModule
{
Push.create("Go ahead, click this notification", {
});
}Rollup会在此代码上触发以下错误:
events.js:160
throw er; // Unhandled 'error' event
^
Error: Unexpected token我是不是做了什么根本不对的事?
发布于 2017-02-09 15:14:50
你离得够近了。但是,至少在当前的转发器(Babel和co.)中,CommonJS模块导出被视为默认导出。这意味着,不必导入所有单独的实体(import * as Push),只需导入默认导出(import Push)即可。
import Push from 'push.js';
class _MyModule
{
constructor() {
Push.create("Go ahead, click this notification", {
});
}
}如何解决CommonJS和ES模块之间的实际互操作性问题还没有最后确定。参见关于这一主题的博客文章。
https://stackoverflow.com/questions/42140049
复制相似问题