Open sergous opened 2 years ago
This is a workaround I used that got me unstuck, without having to painstakingly edit every file Blitz generates: https://gist.github.com/isaacs/4bdeb1d2de48b32e5cd9b668108c1762
It's really not a great idea to rely on any folder in the cwd being a valid top-level import. I know you can configure TypeScript to do this with the tsconfig.json file containing {"compilerOptions":{"baseUrl":"."}}
, but putting the same value in a jsconfig.json
doesn't have the same effect, because "jsconfig.json" is not a thing.
The reason it's not a good idea is that a top-level dependency named app
or db
or mailers
can make things really confusing, if some code in your project wants to import that dependency, and other code is relying on it resolving to the cwd. There's nothing preventing that collision, and it's a footgun waiting for someone to step on it. Much better to be explicit; ideally by generating the full relative path to the actual module in the code Blitz is generating (which, I mean, it's machine generated anyway right? who cares if it has "../../../db"
instead of "db"
, you're creating it programmatically), but failing that, by defining a dependency so that import db from "db"
can only ever resolve to ${baseUrl}/db
, and never any other thing.
Aha! Apparently it is a thing in Webpack, but when loading non-webpack'ed code, it doesn't work. Still, better to be explicit.
What is the problem?
blitz generator creates import line
import db from "db"
When run
blitz console
it can not find import from db.Solution proposition:
The generator should be modified for creating valid db paths
Workaround:
Replace in the generated files the import strings
import db from "db"
with:import db from "../../../db"
(works for queries and mutations)import db from /db/index.js
(works for mutations)Paste all your error logs here:
Paste all relevant code snippets here:
What are detailed steps to reproduce this?
Run
blitz -v
and paste the output here:Please include below any other applicable logs and screenshots that show your problem:
No response