Trying to import locally
Experimenting with Deno v1.6.0 in a testing environment
Attempting local imports using Deno language
Local directory structure:
.
└── src
└── sample
├── hello_world.ts
├── httpRequest.ts
├── localExport
│ └── arithmetic.ts
├── localImport.ts
File to be imported from './localExport/arithmetic.ts':
function add(outbound: number, inbound: number): number {
return outbound + inbound
}
function multiply(sum: number, tax: number): number {
return sum * tax
}
Code in './localImport.ts' file:
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));
To run the above codes:
❯ deno run src/sample/localImportExport.ts
Encountered errors when running:
❯ 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)
Looking for solutions to resolve the issue.