1.0.13 • Published 4 months ago

stx-cli v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

node版本: 18.14.2

项目和模块不在同一个目录下,需要先把模块链接到全局,然后再在项目中链接模块

$ cd xxx/project_npmlink/module1 $ npm link npm link 操作会在全局 node_modules 目录下创建一个 module-name 的超链接。

// 再去项目目录 $ cd xxx/project_npmlink/project1 // 通过包名建立链接 $ npm link module1 此时只需要指定 module-name,

参考资料: https://terwergreen.com/post/use-typescript-to-develop-a-custom-nodejs-frontend-development-scaffold-1i5fne.html#inquirer-%E5%A4%84%E7%90%86%E4%BA%A4%E4%BA%92

https://www.lanmper.cn/ts/t9947 模块化的文章

https://www.totaltypescript.com/relative-import-paths-need-explicit-file-extensions-in-ecmascript-imports

Relative import paths need explicit file extensions in EcmaScript imports

Matt Pocock Matt Pocock Oct 10, 2023

#The Error Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'.

// Relative import paths need explicit file extensions in // EcmaScript imports when '--moduleResolution' is 'node16' // or 'nodenext'.

import { example } from "./foo"; #The Solution That Doesn't Work Adding a .ts extension to the import path doesn't work, and results in the following error:

An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

// An import path can only end with a '.ts' extension when // 'allowImportingTsExtensions' is enabled.

import { example } from "./foo.ts"; #The Solution Add the .js extension to the import path.

import { example } from "./foo.js";

Why Do We Need to Use JS File Extensions?

This error happens because you've specified moduleResolution: NodeNext. This tells TypeScript that you want your imports and exports to conform strictly to the Node spec.

The Node spec requires that you use .js file extensions for all imports and exports. This was decided so that a relative import path like ./foo.js would work both in Node and the browser.

This also simplifies Node's module resolution strategy - Node doesn't have to do any guesswork to figure out what file to import. Thanks to Gil Tayer for clarifying this for me.

#What if I don't want to use JS file extensions? Make sure you're using an external compiler, like esbuild, to compile your TypeScript code. Change your tsconfig.json to use moduleResolution: Bundler instead of moduleResolution: NodeNext.

1.0.13

4 months ago

1.0.12

4 months ago

1.0.11

4 months ago

1.0.10

4 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago