Here are 3 files:
// ./app/index.ts
const app = {
test: 1,
...
}
export default app
// ./app.ts
import app from './app/index'
export default app
// ./index.vue
import { test } from './app.ts'
console.log(test)
When I run index.vue
an error shows:
SyntaxError: The requested module ‘/@fs/Users/VJ/Desktop/project/app.ts?t=1691652606598’ does not provide an export named ‘test’
How can I fix it?
2
Answers
here is the way that should work.
./app/index.ts:
./app.ts:
./index.vue:
For
import { test } from './app.ts'
to workapp.ts
needs to have a named exporttest
. Yours only has a default export.If you don’t want to explicitly export every property of the object I suggest to use object destructuring in
index.vue
:FWIW, if you have to use
app.ts
as intermediate module (for whatever reason) you can rewrite it to