Deno -> 我如何 运行 代码到 运行 而没有错误?
Deno -> How do I run the codes to run without errors?
我想从本地导入
测试环境Deno v1.6.0
我试过 Deno lang 的本地导入
本地目录
.
└── src
└── sample
├── hello_world.ts
├── httpRequest.ts
├── localExport
│ └── arithmetic.ts
├── localImport.ts
'./localExport/arithmetic.ts' 待导入文件
function add(outbound: number, inbound: number): number {
return outbound + inbound
}
function multiply(sum: number, tax: number): number {
return sum * tax
}
'./localImport.ts' 文件到运行
import { add, multiply } from "./localImport/arithmetic.ts";
function totalCost(outbound: number, inbound: number, tax: number): number {
return multiply(add(outbound, inbound), tax);
}
console.log(totalCost(19, 31, 1.2));
console.log(totalCost(45, 27, 1.15));
运行以上代码
❯ deno run src/sample/localImportExport.ts
我收到错误:
❯ deno run src/sample/localImportExport.ts
error: Uncaught SyntaxError: The requested module './localImport/arithmetic.ts' does not provide an export named 'add'
import { add, multiply } from "./localImport/arithmetic.ts";
~~~
at <anonymous> (file:///Users/ko-kamenashi/Desktop/Samples/Deno/deno-sample/src/sample/localImportExport.ts:1:10)
我该怎么办?
错误 The requested module './localImport/arithmetic.ts' does not provide an export named 'add'
告诉您应该使用 export
只需将以下行添加到文件末尾 `export {add, multiply}
'./localExport/arithmetic.ts' 待导入文件
function add(outbound: number, inbound: number): number {
return outbound + inbound
}
function multiply(sum: number, tax: number): number {
return sum * tax
}
export {add, multiply}
我想从本地导入
测试环境Deno v1.6.0
我试过 Deno lang 的本地导入
本地目录
.
└── src
└── sample
├── hello_world.ts
├── httpRequest.ts
├── localExport
│ └── arithmetic.ts
├── localImport.ts
'./localExport/arithmetic.ts' 待导入文件
function add(outbound: number, inbound: number): number {
return outbound + inbound
}
function multiply(sum: number, tax: number): number {
return sum * tax
}
'./localImport.ts' 文件到运行
import { add, multiply } from "./localImport/arithmetic.ts";
function totalCost(outbound: number, inbound: number, tax: number): number {
return multiply(add(outbound, inbound), tax);
}
console.log(totalCost(19, 31, 1.2));
console.log(totalCost(45, 27, 1.15));
运行以上代码
❯ deno run src/sample/localImportExport.ts
我收到错误:
❯ deno run src/sample/localImportExport.ts
error: Uncaught SyntaxError: The requested module './localImport/arithmetic.ts' does not provide an export named 'add'
import { add, multiply } from "./localImport/arithmetic.ts";
~~~
at <anonymous> (file:///Users/ko-kamenashi/Desktop/Samples/Deno/deno-sample/src/sample/localImportExport.ts:1:10)
我该怎么办?
错误 The requested module './localImport/arithmetic.ts' does not provide an export named 'add'
告诉您应该使用 export
只需将以下行添加到文件末尾 `export {add, multiply}
'./localExport/arithmetic.ts' 待导入文件
function add(outbound: number, inbound: number): number {
return outbound + inbound
}
function multiply(sum: number, tax: number): number {
return sum * tax
}
export {add, multiply}