未捕获的TypeError:无法解析模块说明符“ smoothscroll-polyfill”。相对引用必须以“ /”、“./”或“ ../”开头

时间:2020-04-11 18:00:39

标签: javascript npm ecmascript-6 node-modules es6-modules

我从npm安装了一个polyfill作为依赖项,并按上述方式导入模块:

import smoothscroll from 'smoothscroll-polyfill';

smoothscroll.polyfill();

在控制台中显示:

Uncaught TypeError: Failed to resolve module specifier "smoothscroll-polyfill". Relative references must start with either "/", "./", or "../".

将路径更改为:

import smoothscroll from '/node_modules/smoothscroll-polyfill/dist/smoothscroll.min.js';

smoothscroll.polyfill();

它显示:

Uncaught SyntaxError: The requested module '/node_modules/smoothscroll-polyfill/dist/smoothscroll.min.js' does not provide an export named 'default'

我已经尝试过./smoothscroll-polyfill/smoothscroll-polyfill../smoothscroll-polyfillimport * as smoothscroll from 'smoothscroll-polyfill',但是它们都不起作用。

我是ES6模块的新手,没有使用Webpack等捆绑软件。

P.S。此polyfill引用到C:\ Users \ Administrator \ AppData \ Local \ Microsoft \ TypeScript \ 3.8 \ node_modules @ types \ smoothscroll-polyfill \ index.d.ts而不是安装依赖项的路径

0 个答案:

没有答案