【问题标题】:import module for side-effects with Typescript only targeting node使用 Typescript 仅针对节点的副作用的导入模块
【发布时间】:2020-03-25 06:20:50
【问题描述】:

给定:

一个带有import 但没有export 调用的ts 模块,名为./sn-ps.ts
一个名为 ./main.ts
的 ts 模块 一个tsconfig如下...

{
  "compilerOptions": {
    "target": "ESNext",                          
    "module": "commonjs",                     
    "allowJs": true,                       
    "checkJs": true,                       
    "sourceMap": true,                     
    "downlevelIteration": true,            
    "noImplicitAny": true,                 
    "moduleResolution": "node",            
    "allowSyntheticDefaultImports": true,  
    "esModuleInterop": true,                   
    "baseUrl": ".",
  },
  "exclude": [
    "node_modules"
  ]
}

问题:

如何在 ./main 模块中导入 ./sn-ps 文件,这样我才能确定 ./sn-ps 是否在 ./main 之前运行?

我尝试了import from "./snippet";import * as arbitrarySymbol from "./snippet"; 以及变体,但没有成功。

【问题讨论】:

    标签: node.js typescript module


    【解决方案1】:
    import "./snippet";
    

    应该按照here 中描述的方式进行操作

    【讨论】:

      猜你喜欢
      • 2013-08-25
      • 1970-01-01
      • 2012-11-03
      • 2017-04-03
      • 2016-12-11
      • 1970-01-01
      • 2018-01-27
      • 2018-08-07
      相关资源
      最近更新 更多