Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types are loadable from referenced project but code is not #54

Closed
1 task
vlovich opened this issue Jun 30, 2022 · 1 comment
Closed
1 task

Types are loadable from referenced project but code is not #54

vlovich opened this issue Jun 30, 2022 · 1 comment

Comments

@vlovich
Copy link

vlovich commented Jun 30, 2022

Bug description

When I run this:

import { test } from 'src/util/some-module'
console.log(test())

I get

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'src' imported from ...elided.../scripts/src/some-utility/main.ts
    at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:908:9)
    at moduleResolve (node:internal/modules/esm/resolve:957:20)
    at defaultResolve (node:internal/modules/esm/resolve:1173:11)
    at u (file://...elided.../scripts/src/some-utility/node_modules/@esbuild-kit/esm-loader/dist/index.js:1:2362)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async J (file://...elided.../scripts/src/some-utility/node_modules/@esbuild-kit/esm-loader/dist/index.js:1:1584)
    at async u (file://...elided.../scripts/src/some-utility/node_modules/@esbuild-kit/esm-loader/dist/index.js:1:2512)
    at async ESMLoader.resolve (node:internal/modules/esm/loader:604:24)
    at async ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:7)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:82:21)
    at async Promise.all (index 0)
    at async link (node:internal/modules/esm/module_job:87:9) {
  code: 'ERR_MODULE_NOT_FOUND'

I can import types from src but actual code fails to load for whatever reason. Running tsc for type checking passes but eslint complains so maybe this is something weird with my TSC & not specific to tsx? I'm at a loss though.

...elided.../scripts/src/some-utility/main.ts
  4:13  error  Unsafe call of an `any` typed value  @typescript-eslint/no-unsafe-call

Reproduction

I have the following (simplified) directory layout:

src/
   tsconfig.json
   project/api.ts
   util/some-module.ts
scripts/src/some-utility
   tsconfig.json
   main.ts

All the source in the project is TypeScript using ESM modules. The tsconfig for some-utility looks like this:

{
  "extends": "../tsconfig.json",
  "references": [{ "path": "../../../src" }],
}

The referenced tsconfig is:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["esnext"],
    "alwaysStrict": true,
    "strict": true,
    "noEmitOnError": true,
    "module": "esnext",
    "moduleResolution": "node",
    "outDir": "./../../tscOutDir",
    "esModuleInterop": true,
    "types": ["@types/node"],
    "sourceMap": true,
    "paths": {
      "src/*": ["./../../src/*"]
    }
  }
}

src/tsconfig is as follows:

{
  "extends": "../tsconfig.json",
  "include": ["./**/*"],
  "compilerOptions": {
    "composite": true,
    "types": ["@cloudflare/workers-types"]
  }
}

The tsconfig it inherits is:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "src/*": ["./src/*"],
      "testing/*": ["./testing/*"]
    },
    "target": "esnext",
    "lib": ["esnext"],
    "alwaysStrict": true,
    "strict": true,
    "noEmitOnError": true,
    "moduleResolution": "node",
    "outDir": "tscOutDir",
    "preserveConstEnums": true,
    "esModuleInterop": true
  }
}

Environment

System:
    OS: Linux 5.16 Arch Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 3.54 GB / 31.07 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 17.9.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.5.5 - /usr/bin/npm
  npmPackages:
    tsx: ^3.4.3 => 3.4.3

Can you contribute a fix?

  • I’m interested in opening a pull request for this issue.
@vlovich vlovich added bug Something isn't working pending triage labels Jun 30, 2022
@privatenumber
Copy link
Owner

privatenumber commented Jul 1, 2022

Thanks for your issue.

Can you provide a link to a minimal reproduction repository?

What you provided is not sufficient. If it's a single file or two, I wouldn't mind to re-create it, but you have a bunch of files and only of tsconfigs. Nothing I can run to reproduce and debug.

Happy to reopen when provided.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants