我从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-polyfill
,import * 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而不是安装依赖项的路径