typescript 未找到 Angular4.x 模块:错误:无法解析“classlist.js”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48688818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:13:07  来源:igfitidea点击:

Angular4.x Module not found: Error: Can't resolve 'classlist.js'

angulartypescriptangular-cli

提问by MayureshP

When I remove comment part in polyfills.ts for polyfills to load page in Internet Explore

当我删除 polyfills.ts 中的注释部分以便 polyfills 在 Internet Explorer 中加载页面时

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
 import 'core-js/es6/symbol';
 import 'core-js/es6/object';
 import 'core-js/es6/function';
 import 'core-js/es6/parse-int';
 import 'core-js/es6/parse-float';
 import 'core-js/es6/number';
 import 'core-js/es6/math';
 import 'core-js/es6/string';
 import 'core-js/es6/date';
 import 'core-js/es6/array';
 import 'core-js/es6/regexp';
 import 'core-js/es6/map';
 import 'core-js/es6/weak-map';
 import 'core-js/es6/set';
 import 'reflect-metadata';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
 import 'classlist.js';  // Run `npm install --save classlist.js`.

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/**
 * Required to support Web Animations `@angular/animation`.
 * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
 **/
 import 'web-animations-js';  // Run `npm install --save web-animations-js`.

But if we do build using angular cli. it throws error in console I did run this command in project "npm install --save classlist.js"

但是,如果我们确实使用 angular cli 进行构建。它在控制台中抛出错误我确实在项目“npm install --save classlist.js”中运行了这个命令

Module not found: Error: Can't resolve 'classlist.js' in src
 @ ./src/polyfills.ts 36:0-22
 @ multi ./src/polyfills.ts

Please suggest solution

请提出解决方案

回答by Daniel Netzer

remove the current package,

删除当前包,

npm uninstall classlist.js --save

then run

然后运行

npm cache verify

afterwards run

之后运行

npm install classlist.js --save-exact

回答by Manduro

You're importing a polyfill that is not included by default. You have to install it as a dependency first. How to do that is in a comment on the same line that imports it:

您正在导入默认情况下不包含的 polyfill。您必须首先将其安装为依赖项。如何做到这一点在导入它的同一行的注释中:

// Run `npm install --save classlist.js`.

The same goes for the web-animations-jspolyfill if you haven't done so already.

web-animations-js如果您还没有这样做的话,polyfill 也是如此。

回答by Harjinder Pal Singh

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
         import 'core-js/es6/symbol';
         import 'core-js/es6/object';
         import 'core-js/es6/function';
         import 'core-js/es6/parse-int';
         import 'core-js/es6/parse-float';
         import 'core-js/es6/number';
         import 'core-js/es6/math';
         import 'core-js/es6/string';
         import 'core-js/es6/date';
         import 'core-js/es6/array';
         import 'core-js/es6/regexp';
         import 'core-js/es6/map';
         import 'core-js/es6/weak-map';
         import 'core-js/es6/set';

回答by Harjinder Pal Singh

Run the following commands in terminal/command prompt:

在终端/命令提示符中运行以下命令:

  1. npm install --save classlist.js
  2. npm install --save web-animations-js
  1. npm install --save classlist.js
  2. npm install --save web-animations-js