[英]Trying to understand how "module" & "moduleResolution" differ,
"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 项目有一个基本的了解。
What is the difference between "module" & "moduleResolution"? “模块”和“模块分辨率”有什么区别?
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 有什么影响?
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.