Open w0rldart opened 1 year ago
You need to set your tsconfig moduleResolution
option to node16
or nodenext
: https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing
Thank you ephys for the reply. I will try it, but it doesn't make sense.
Your own tsconfig has moduleResolution
set just to node
, like I do
If this turns out to be the issue, may I suggest that this is clearly reflected somewhere in the documentation?
Our own tsconfig should not be used as an example, it's overly complicated because we try to support multiple versions of TypeScript
I've converted this to a documentation issue
Our own tsconfig should not be used as an example, it's overly complicated because we try to support multiple versions of TypeScript
I've converted this to a documentation issue
It would be handy to have an example tsconfig.json
that's suitable to use in a fresh V7 project
This is pretty awful, I can't lie. NodeNext
is practically unusable due to
../../
, that is an abomination)The exports
block is a lovely QoL feature when you're on NodeNext, but NodeNext being required to use v7 at all? :weary:
You can have path aliasing in your own project by configuring exports
in your own package.json
The explanation for the different type of moduleResolutions is described here: https://www.typescriptlang.org/tsconfig#moduleResolution If that is not sufficient, I would recommend opening an issue on the TypeScript repo about it instead
You don't technically have to use Node16/NodeNext/Bundler (though I don't see why you wouldn't use the ts module resolution that accurately replicates how node resolves modules if you're using node). You can configure paths
, or use resolvePackageJsonExports
instead
yeah, sorry. Was very frustrated last night. Turned out my path aliasing was working just fine but needed the .js
extensions - the error was incredibly vague ('cannot resolve...')
We have opened https://github.com/sequelize/website/pull/583 to document this. Are we missing anything?
As mentioned in https://github.com/sequelize/sequelize/issues/16866, we also need to update the SSCCE repo's tsconfig
FWIW, you can set moduleResolution
to "Bundler" and it also works. (TS notes that "This is the recommended setting in TypeScript 5.0+ for applications that use a bundler.")
I have Sequelize v7 with decorators working in a Next.js 14 project, and I'm basically using the default create-t3-app tsconfig.json
. Posting this here in case anyone needs a similar resolution:
{
"compilerOptions": {
/* Base Options */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ES2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
/* Sequelize */
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowImportingTsExtensions": true,
/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"checkJs": true,
/* Bundled projects */
"lib": ["dom", "dom.iterable", "ES2022"],
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true,
/* Path aliases */
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
},
/* Needed for ts-node */
"typeRoots": ["**/*.d.ts"]
},
"include": [
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"],
"ts-node": {
"esm": true
}
}
Issue Creation Checklist
Bug Description
The documentation explicitly indicates to use decorators to define all aspects related to a model. From types, to relationships, and more.
However, I personally cannot get it to work, due to this issue in my VSCode editor
Reproducible Example
node_modules
seems to have all the requested dataHowever, and as per a standard example on this page, the usual flow to use decorators
has the second line, no matter what else I have in my file, always throw this error:
Cannot find module '@sequelize/core/decorators-legacy' or its corresponding type declarations.ts(2307)
What do you expect to happen?
Find the module and not throw that error
What is actually happening?
Environment
tsconfig.json
MySQL 8
mysql2@3.5.2
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.