-
This might also be a feature request for the docs: I am having an existing project with a Nuxt app (Vue) and an existing backend API. Both share code (interfaces, enums, constants, Zod schemas) by a shared library. I decided to replace the existing backend with Adonis but I cant import anything from my shared library within Adonisjs. I am getting errors like Until now an import looked like this:
Which is an index.ts file:
Both the Nuxt app as my library are ESM modules so I dont understand why I cant simply import it as before. And I dont understand why I need to add tsconfig.json:
package.json
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This is because that's how the ESM spec implementation works in Node.js. I have pasted a screenshot from the Node.js docs. https://nodejs.org/api/esm.html Now, you might be aware of the Node.js behavior and wondering why do I have to import a TypeScript file with This article does a great job at explaining it. https://www.totaltypescript.com/relative-import-paths-need-explicit-file-extensions-in-ecmascript-imports |
Beta Was this translation helpful? Give feedback.
-
To answer my own question: In the shared library tsconfig set target and module to Now imports work both in Adonis and in the frontend framework (Nuxt in my case). |
Beta Was this translation helpful? Give feedback.
To answer my own question:
In the shared library tsconfig set target and module to
ESNext
and module resoltion toNodeNext
. Now change all imports/exports to have .js extension.Now imports work both in Adonis and in the frontend framework (Nuxt in my case).