Angular4.x Module not found: Error: Can't reso

2020-06-08 08:27发布

问题:

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

/** 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"

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

Please suggest solution

回答1:

remove the current package,

npm uninstall classlist.js --save

then run

npm cache verify

afterwards run

npm install classlist.js --save-exact


回答2:

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:

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

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



回答3:

/** 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';


回答4:

Run the following commands in terminal/command prompt:

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