OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure Functions Typescript Compiles but Can't Find Module at Runtime

  • Thread starter Thread starter Iden Busia
  • Start date Start date
I

Iden Busia

Guest
I have written a declaration library in TS that I've turned into a Node module. It consists entirely of .d.ts files, including an index.d.ts like this:

Code:
export * from "./file1";
export * from "./file2";
export * from "./file3";

it has this package.json:

Code:
{
  "description": "Types for foo repository",
  "license": "UNLICENSED",
  "name": "@company/foo",
  "main": "",
  "types": "index.d.ts",
  "repository": {
    "type": "git",
    "url": "https://github.com/company/repo.git"
  },
  "version": "1.0.4"
}

This setup looks exactly like another package we're depending on; luxon.

tsc works fine, and even VSCode is linking the files correctly in imports (no errors). However, at runtime I get "cannot find module" errors:

Code:
[2024-06-21T17:39:35.273Z] Worker was unable to load function Function: 'Cannot find module '@company/foo'
[2024-06-21T17:39:35.273Z] Worker failed to load function: 'Function' with functionId: 'fejaklvc-afae-4aee-adc4-a635657141dc'.
[2024-06-21T17:39:35.276Z] Require stack:
[2024-06-21T17:39:35.277Z] Result: Failure
[2024-06-21T17:39:35.277Z] - /home/person/dev/repo/api/dist/Function/types.js

When I go to /home/person/dev/repo/api/dist/Function/types.js in VSCode it doesn't show any errors in the require. Tsconfig.json:

Code:
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "ESNext",
    "outDir": "dist",
    "rootDir": ".",
    "disableSourceOfProjectReferenceRedirect": true,
    "sourceMap": true,
    "strict": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "composite": true,
    "typeRoots": ["node_modules/@types", "src/typings"],
    "paths": {
      "*": ["./common/@types/*"]
    }
  }
}

I have tried different targets. Totally lost. Why won't it find the module at runtime?

  • I've tried different targets in the tsconfig. No change.

<p>I have written a declaration library in TS that I've turned into a Node module. It consists entirely of .d.ts files, including an index.d.ts like this:</p>
<pre><code>export * from "./file1";
export * from "./file2";
export * from "./file3";
</code></pre>
<p>it has this package.json:</p>
<pre><code>{
"description": "Types for foo repository",
"license": "UNLICENSED",
"name": "@company/foo",
"main": "",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/company/repo.git"
},
"version": "1.0.4"
}
</code></pre>
<p>This setup looks exactly like another package we're depending on; luxon.</p>
<p>tsc works fine, and even VSCode is linking the files correctly in imports (no errors). However, at runtime I get "cannot find module" errors:</p>
<pre><code>[2024-06-21T17:39:35.273Z] Worker was unable to load function Function: 'Cannot find module '@company/foo'
[2024-06-21T17:39:35.273Z] Worker failed to load function: 'Function' with functionId: 'fejaklvc-afae-4aee-adc4-a635657141dc'.
[2024-06-21T17:39:35.276Z] Require stack:
[2024-06-21T17:39:35.277Z] Result: Failure
[2024-06-21T17:39:35.277Z] - /home/person/dev/repo/api/dist/Function/types.js
</code></pre>
<p>When I go to /home/person/dev/repo/api/dist/Function/types.js in VSCode it doesn't show any errors in the require. Tsconfig.json:</p>
<pre><code>{
"compilerOptions": {
"module": "commonjs",
"target": "ESNext",
"outDir": "dist",
"rootDir": ".",
"disableSourceOfProjectReferenceRedirect": true,
"sourceMap": true,
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"composite": true,
"typeRoots": ["node_modules/@types", "src/typings"],
"paths": {
"*": ["./common/@types/*"]
}
}
}
</code></pre>
<p>I have tried different targets. Totally lost. Why won't it find the module at runtime?</p>
<ul>
<li>I've tried different targets in the tsconfig. No change.</li>
</ul>
 
Top