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.

TS2307: Cannot find module when pure ESM packages with Vue SFC files

See original GitHub issue
{
  "name": "test-a",
  "version": "1.0.0",
  "exports": {
    ".": "./index.js",
    "./components/date-picker": "./components/date-picker/index.vue"
  }
}
// GET TS2307 error
import DatePicker from 'test-a/components/date-picker'

Repro case: https://github.com/yoyo930021/volar-pure-esm-project-bug/blob/main/src/app.vue#L17

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yoyo930021commented, Nov 10, 2022

@yoyo930021, change the path to:

import DatePicker from 'test-a/components/date-picker/index.vue'

Since you are using an SFC, maybe you don’t need a directory for that component?

This is unsafe code. It is broken when package internal changed. It also does not meet the ESM.

0reactions
yoyo930021commented, Nov 12, 2022

@yoyo930021, change the path to:

import DatePicker from 'test-a/components/date-picker/index.vue'

Since you are using an SFC, maybe you don’t need a directory for that component?

This is unsafe code. It is broken when package internal changed. It also does not meet the ESM.

Then why resolve to the index file in your package.json?

{
  "name": "test-a",
  "version": "1.0.0",
  "exports": {
    ".": "./index.js",
    "./components/date-picker": "./components/date-picker/index.vue"
  }
}

It have same problem. They are the temp workrounds.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode showing "cannot find module" TS error for .vue import ...
vue extension on the import, I resolved this error by adding typescript shims for vue files. I created a file in typings/sfc.d.ts containing ......
Read more >
IDE reports TS2307: Cannot find module error for Vue ...
The workaround is to split declare module and declare global into two separate files. The first declare module is called ambient module, which ......
Read more >
TypeScript cannot find module (vue file) when the path is ...
I am trying to import LoginForm.vue from ./resources/scripts/views/auth/LoginForm but TypeScript won't recognize the path.
Read more >
Getting started with Vite and Vue 3 | Ninja Squad
This is called a Single File Component, or SFC. The CLI is overall super handy to avoid having to learn and configure all...
Read more >
ts2307: cannot find module '*.vue' or its corresponding type ...
I have got a Vue3 project running through Vite and trying to import my Vue3 component files in my App.vue . But instead...
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