BuilderIO / gpt-crawler

Crawl a site to generate knowledge files to create your own custom GPT from a URL
https://www.builder.io/blog/custom-gpt
ISC License
18.14k stars 1.88k forks source link

'Zod' package not found | #123

Open Daethyra opened 6 months ago

Daethyra commented 6 months ago

[ERR_MODULE_NOT_FOUND]

I ran into this error after the docker container successfully builds. I use docker build -t gpt-crawer . ; docker run -it gpt-crawler. Before today, I've never had an issue. The traceback error pops specifically when the docker run command is ran.

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from /home/myuser/dist/src/config.js at new NodeError (node:internal/errors:405:5) at packageResolve (node:internal/modules/esm/resolve:916:9) at moduleResolve (node:internal/modules/esm/resolve:973:20) at defaultResolve (node:internal/modules/esm/resolve:1193:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12) at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38) at ModuleWrap. (node:internal/modules/esm/module_job:76:39) at link (node:internal/modules/esm/module_job:75:36) { code: 'ERR_MODULE_NOT_FOUND' }

Node.js v18.19.0



## Attempted Fix
I tried following the top comment from [this Stack Overflow](https://stackoverflow.com/questions/65384754/error-err-module-not-found-cannot-find-module "Attempted Fix") thread but to no avail. I don't know JS/TS so I can't troubleshoot on my own. Any help would be appreciated.

- Quote:

When you are using ECMAScript modules you are forced to provide the file extension: https://nodejs.org/api/esm.html#esm_mandatory_file_extensions

So, on top of what other suggested of using `"type": "module"` on package.json you also need to specify the file extension `import {urls} from './helpers.js'`. You can also use the flag  `--es-module-specifier-resolution=node` to make it resolve js files as modules just like it did before with `require`
Daethyra commented 6 months ago

Successful bandaid fix: I changed a line in the root dir's Dockerfile:

Consider that the inclusion of developer dependencies during building of the final image resolved the [ERR_MODULE_NOT_FOUND], AND I wasn't able to find zod inside /home/myuser/node_modules when developer dependencies were omitted.

These two things suggest there may be a potential issue with how dependencies are being handled during the Docker build process. Not that I trust it, but LLMs I've asked about this question say it could be an issue of NODE_ENV's setup. I'm no JavaScript/TypeScript developer, so I really have no idea what the right fix for this issue is.


I don't like including developer dependencies in a final image. I would really appreciate the input of someone who knows JS/TS and this project better than I.