In Angular project, dependency is imported using "require" instead of ES6 import

In my Angular project, I have a dependency on moment.js.

When trying to auto-import, it will Webstorm will import using require() instead of using ES6 syntax.

The correct syntax is shown in the popup: https://prnt.sc/skhuo7

However, clicking that option imports the dependency like this: https://prnt.sc/skhw2q

0

Import 'moment' from module moment quick fix comes from tsserver (Typescript compiler service), not from IDE. And it's just an action name, not a syntax:)

Import syntax depends on a way module is exported. When exporting a module using export =, TypeScript-specific import module = require("module") must be used to import the module. See https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

1

请先登录再写评论。