TS1148 ~ How to “import” with --module: “none” and typescript 2.x

后端 未结 4 2141
一生所求
一生所求 2021-02-14 19:02

I\'m currently working on a project with some legacy javascript. The application does not include a module loader, it just puts everything as a global into the window object. To

4条回答
  •  青春惊慌失措
    2021-02-14 19:20

    That's not actually true that you can't import modules. You can do a few things to import modules in this scenario:

    1. Target ES6 instead. With "target": "es6", you can leave "module": "none"` in place and your imports will work just fine.
    2. Change "module": "none" to "module": "commonjs" and add "moduleResolution": "node" - this will provide a means to handle imports in ES5 syntax.

提交回复
热议问题