question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

#5539 (confusion about `.js`/`.ts`) is happening again

See original GitHub issue

Describe the bug

on "vite": "^3.2.3", trying to work with: "@libp2p/kad-dht": "^6.0.1"

the latter contains the line in routing-table/index.ts:

import * as utils from '../utils.js'

which leads vite to die with the error message:

15:06:54 [vite] Internal server error: Failed to resolve import "../utils.js" from "node_modules/@libp2p/kad-dht/src/routing-table/index.ts?v=d74ebf31". Does the file exist?
  Plugin: vite:import-analysis
  File: /home/kyra/dev/abyssnet/abyssnet/node_modules/@libp2p/kad-dht/src/routing-table/index.ts?v=d74ebf31:3:23
  1  |  import KBuck from "k-bucket";
  2  |  import * as utils from "../utils.js";
     |                          ^
  3  |  import Queue from "p-queue";
  4  |  import { TimeoutController } from "timeout-abort-controller";
      at formatError (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:39975:46)
      at TransformContext.error (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:39971:19)
      at normalizeUrl (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:36839:33)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async TransformContext.transform (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:36972:47)
      at async Object.transform (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:40228:30)
      at async loadAndTransform (file:///home/kyra/dev/abyssnet/abyssnet/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:36615:29)

the file it’s looking for exists in ../utils.ts because typescript loooooves “potential future paths” apparently

and yes, i am aware this is a dupe of #5539, as the title suggests, but that one is “fixed” since 2.x and locked.

Reproduction

https://stackblitz.com/edit/vitejs-vite-n3653t?file=main.js

Steps to reproduce

the reproduction link already does most of this, but apparently it didn’t quite save anything. make sure to:

  • devdepend on vite
  • depend on kad-dht
  • import { kadDHT } from '@libp2p/kad-dht' in any js file
  • run the vite live server (or build, for that matter)
  • “profit”

System Info

System:
    OS: Linux 5.19 Void
    CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
    Memory: 3.16 GB / 31.30 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.15.1 - /bin/node
    Yarn: 1.22.18 - /bin/yarn
    npm: 8.11.0 - /bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^3.2.0 => 3.2.0 
    vite: ^3.2.3 => 3.2.4

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Nov 25, 2022

Maybe? I’ll close this issue for now but feel free to create a new issue if you achieved to create a repro.

0reactions
nonchipcommented, Nov 25, 2022

i’m sorry, you’re right there, that makes it work for me now too, i did see the error in the example i tried to share, but that didn’t save correctly. my actual project worked for ages with only this hack:

  resolve: {
    alias: [
      {
        find: "buffer",
        replacement: './node_modules/buffer/index.js',
      },
      {
        find: "../utils.js",
        replacement: "./node_modules/@libp2p/kad-dht/src/utils.ts",
      },
    ]
  }

but now it somehow seems to be content with out them even though i didn’t change anything related to that in the meantime. maybe somehow my installation got temporarily broken?

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-cli@next: Error: Cannot find module 'babel-code-frame ...
Using gatsby-cli@next , the package @babel/code-frame is referred to in the package.json using the new npm scoped package notation (with @ ), but...
Read more >
Teradata/covalent - Gitter
Yep, whenever any of those happen, you git the serve ... @ghost~5539edbc15522ed4b3df7357 ... its between san diego CA, santa clara CA and austin...
Read more >
Albuquerque Morning Journal, 02-24-1907 - UNM Digital Repository
Every- thing thai ever happened between them seems lo be known to the pros- - ecutor. win n the trial is resumed Monday,....
Read more >
Page 8 — Indianapolis Recorder 11 June 1949 — Hoosier State ...
After the altercation, believing her husband, who was undressed and in bed, was going to reach for the gun. Mrs. Selectman said, she...
Read more >
Reliable pattern recognition system with novel semi-supervised ...
This similarity may account for the confusion of numerals and the lower performances when compared with handwritten numeral recognition in general [4].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found