简体   繁体   English

试图了解“module”和“moduleResolution”的不同之处,

[英]Trying to understand how "module" & "moduleResolution" differ,

I fail to understand why there is both a "module" & "moduleResolution" setting.我不明白为什么同时存在"module""moduleResolution"设置。

I have always thought of a module, as being nothing more than a specification (and/or standard) that defines the way that software-packages "resolve", and are "resolved-by", other software packages that adhere to the same specification (and/or standard) .我一直认为一个模块只不过是一个规范(和/或标准) ,它定义了软件包“解析”“解析”的方式,其他软件包遵循相同的规范(和/或标准)

Maybe that is an accurate perception, maybe not, either way, I don't see any reason for configuring the module type, and the moduleResolution separately.也许这是一个准确的看法,也许不是,无论哪种方式,我都看不出有任何理由分别配置module类型和moduleResolution I am not criticizing TypeScript here, I know with 100% certainty, that I am the one lacking, not TypeScript.我不是在这里批评 TypeScript,我 100% 肯定地知道,我是缺乏的人,而不是 TypeScript。 I am just trying to get a fundamental understanding for how to configure my TypeScript projects.我只是想对如何配置我的 TypeScript 项目有一个基本的了解。


  1. What is the difference between "module" & "moduleResolution"? “模块”和“模块分辨率”有什么区别?

  2. How does the tsconfig.json setting module affect the modules (or packages) being imported by a project? tsconfig.json设置module如何影响项目正在导入的模块(或包)? And what impact does it have on the JavaScript that is transpilled and emitted by the TypeScript compiler tsc ?它对 TypeScript 编译器tsc转换和发出的 JavaScript 有什么影响?

  3. How does the tsconfig.json setting moduleResolution affect the modules (or packages) being imported by a project? tsconfig.json设置moduleResolution如何影响项目导入的模块(或包)? And what impact does it have on the JavaScript that is transpilled and emitted by the TypeScript compiler tsc ?它对 TypeScript 编译器tsc转换和发出的 JavaScript 有什么影响?

moduleResolution determines the algorithm used for finding/resolving modules eg looking in node_modules or searching relative paths moduleResolution确定用于查找/解析模块的算法,例如查看node_modules或搜索相对路径

module determines the type of import/export used - module确定使用的导入/导出类型-

// CommonJS
const zip = require("./ZipCodeValidator");

// ES2020
import { valueOfPi } from "./constants";

For module node12/nodenext对于module node12/nodenext

node12/nodenext (nightly builds) Available in nightly builds, the experimental node12 and nodenext modes integrate with Node's native ECMAScript Module support. node12/nodenext(夜间构建) 在夜间构建中可用,实验性的 node12 和 nodeext 模式与 Node 的原生 ECMAScript 模块支持集成。 The emitted JavaScript uses either CommonJS or ES2020 output depending on the file extension and the value of the type setting in the nearest package.json.发出的 JavaScript 使用 CommonJS 或 ES2020 输出,具体取决于文件扩展名和最近的 package.json 中类型设置的值。 Module resolution also works differently.模块分辨率的工作方式也不同。 You can learn more in the handbook您可以在手册中了解更多信息

The docs are a bit behind for node16 but they're beingupdated node16的文档有点落后,但正在更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Typescript compilerOptions module & moduleResolution - Typescript compilerOptions module & moduleResolution 找不到模块“ts-transformer-keys”。 您的意思是将“moduleResolution”选项设置为“node”,还是将别名添加到“paths”选项? - Cannot find module 'ts-transformer-keys'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? 试图了解Angular 2中的承诺 - Trying to understand the Promise in angular 2 TypeScript 与经典模块解决工作不正确 - TypeScript with classic moduleResolution work incorrect 试图了解Typescript泛型 - Trying to understand Typescript generics 试图了解RxJS导入 - Trying to understand RxJS imports 试图了解 Angular v4.4 实际上如何与 platformBrowserDynamic 和 PlatformRef 一起使用 - Trying to understand how Angular v4.4 actually works with platformBrowserDynamic and PlatformRef 我无法理解 generics 在 nodejs 模块 http.d.ts 中的这段代码中是如何使用的 - I am not able to understand how generics are used in this code in nodejs module http.d.ts 如何理解 NavLinkProps 接口? - How to understand NavLinkProps Interface? typescript baseUrl 标志是否覆盖了 moduleResolution: 节点的解析机制? - Does typescript baseUrl flag override the resolution mechanism of moduleResolution: node?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM