redwood icon indicating copy to clipboard operation
redwood copied to clipboard

`rw build --side=api` ignores redwood.toml's [api] path configuration

Open mmmeff opened this issue 2 years ago • 9 comments

Description

The command, yarn rw build --side=api breaks on prisma schema loading when using a custom path for the API project. yarn rw build api also fails the same way.

Reproduction Steps

  1. create a fresh redwood project with yarn create redwood-app
  2. create a new directory in the root of the project, apps
  3. Move the api directory created by redwood into the new apps directory
  4. Edit redwood.toml and set the path config option under [api] to "./apps/api"
  5. Run yarn rw build --side=api

Expected Output

Build succeeds

Actual Output

▶ yarn rw build --side=api
Skipping database and Prisma client generation, no `schema.prisma` file found: `/Users/jdoe/code/example/api/db/schema.prisma`
  ✖ Generating Prisma Client...
    → The "file" argument must be of type string. Received undefined
    Verifying graphql schema...
    Building API...
Command failed with ERR_INVALID_ARG_TYPE: 
The "file" argument must be of type string. Received undefined

mmmeff avatar Jun 21 '22 00:06 mmmeff

I'm also seeing this error when running yarn rw g sdl <Model> without a root ./web folder. redwood.toml's [web] path is set to the correct folder for the web project

▶ yarn rw g sdl Part -f
yarn run v1.22.19
$ <redacted>/node_modules/.bin/rw g sdl Part -f
  ✔ Generating SDL files...
    ✔ Successfully wrote file `./api/src/graphql/parts.sdl.ts`
    ✔ Successfully wrote file `./api/src/services/parts/parts.scen
arios.ts`
    ✔ Successfully wrote file `./api/src/services/parts/parts.test
.ts`
    ✔ Successfully wrote file `./api/src/services/parts/parts.ts`
  ✖ Generating types ...
    → The "path" argument must be of type string or an instance of
…
The "path" argument must be of type string or an instance of Buffer or URL. Received null
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

mmmeff avatar Jun 27 '22 16:06 mmmeff

It seems to me that somewhere in the build tools with have the api path hardcoded, OR maybe the toml setting isn't being picked up.

@dthyresson ok to pick up?

dac09 avatar Jun 27 '22 18:06 dac09

Verbose output:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
    at Object.openSync (node:fs:577:10)
    at Object.readFileSync (node:fs:453:35)
    at fileToAst (/Users/jdoe/code/redacted/node_modules/@redwoodjs/internal/dist/ast.js:36:28)
    at generateTypeDefRouterRoutes (/Users/jdoe/code/redacted/node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js:177:34)
    at generateTypeDefs (/Users/jdoe/code/redacted/node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js:64:148)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async generate (/Users/jdoe/code/redacted/node_modules/@redwoodjs/internal/dist/generate/generate.js:26:25)
    at async run (/Users/jdoe/code/redacted/node_modules/@redwoodjs/internal/dist/generate/generate.js:37:17) {
  code: 'ERR_INVALID_ARG_TYPE'
}

mmmeff avatar Jun 30 '22 20:06 mmmeff

Thanks @mmmeff - I suspect this is one of those features we had originally planned - but then fell off our radar!

For now I don't believe Redwood supports customising the path to web and api folders (although I can totally understand why you would think we do). We'll look to fix this!

dac09 avatar Jun 30 '22 20:06 dac09

@mmmeff - could I ask that you give us an idea of why this feature would be important to you? This is definitely a bug/missing feature - but it would be very helpful to understand your reasoning behind this.

dac09 avatar Jul 06 '22 18:07 dac09

  1. It's listed as a feature/option in the Redwood.toml docs but does nothing
  2. I want to control the folder structure of my codebase. Specifically, I want to group both API and web under a common ./apps directory
  3. I only want to use Redwood's API and have set up a Next.js project in place of the web project.

mmmeff avatar Jul 06 '22 19:07 mmmeff

For anyone else who runs into this, I've worked around it in the meantime by creating a few dummy files in a web directory.

Create these files and the path exceptions should stop throwing in Redwood 2.x:

  • web/src/App.ts
  • web/src/index.html
  • web/src/Routes.ts

They can all be empty

mmmeff avatar Jul 06 '22 19:07 mmmeff

i have the same error

#27 [api_build 2/2] RUN yarn rw build api
#27 11.13 rw build [side..]
#27 11.13 
#27 11.13 Build for production
#27 11.13 
#27 11.13 Positionals:
#27 11.13   side  Which side(s) to build
#27 11.13                         [array] [choices: "web", "api"] [default: ["web","api"]]
#27 11.13 
#27 11.13 Options:
#27 11.13       --help                 Show help                                 [boolean]
#27 11.13       --version              Show version number                       [boolean]
#27 11.13       --cwd                  Working directory to use (where `redwood.toml` is
#27 11.13                              located.)
#27 11.13       --stats                Use Webpack Bundle Analyzer (​https://github.com/we
#27 11.13                              bpack-contrib/webpack-bundle-analyzer​)
#27 11.13                                                       [boolean] [default: false]
#27 11.13   -v, --verbose              Print more               [boolean] [default: false]
#27 11.13       --prerender            Prerender after building web
#27 11.13                                                        [boolean] [default: true]
#27 11.13       --prisma, --db         Generate the Prisma client[boolean] [default: true]
#27 11.13       --performance, --perf  Measure build performance[boolean] [default: false]
#27 11.13 
#27 11.13 Also see the Redwood CLI Reference
#27 11.13 (​[https://redwoodjs.com/docs/cli-commands#build​)](https://redwoodjs.com/docs/cli-commands#build%E2%80%8B))
#27 11.13 
#27 11.15 TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
#27 11.15     at Object.openSync (node:fs:586:10)
#27 11.15     at Object.readFileSync (node:fs:462:35)
#27 11.15     at DefaultHost.readFileSync (/app/node_modules/@redwoodjs/structure/dist/hosts.js:35:15)
#27 11.15     at RWRouter.get text (/app/node_modules/@redwoodjs/structure/dist/ide.js:241:22)
#27 11.15     at Object.getterCommon (/app/node_modules/lazy-get-decorator/common.js:23:32)
#27 11.15     at RWRouter.get (/app/node_modules/lazy-get-decorator/legacy.js:19:29)
#27 11.15     at RWRouter.get sf (/app/node_modules/@redwoodjs/structure/dist/ide.js:253:21)
#27 11.15     at Object.getterCommon (/app/node_modules/lazy-get-decorator/common.js:23:32)
#27 11.15     at RWRouter.get (/app/node_modules/lazy-get-decorator/legacy.js:19:29)
#27 11.15     at RWRouter.get jsxNode (/app/node_modules/@redwoodjs/structure/dist/model/RWRouter.js:86:48) {
#27 11.15   code: 'ERR_INVALID_ARG_TYPE'
#27 11.15 }
#27 ERROR: executor failed running [/bin/sh -c yarn rw build api]: exit code: 1
------
 > [api_build 2/2] RUN yarn rw build api:
#27 11.15     at DefaultHost.readFileSync (/app/node_modules/@redwoodjs/structure/dist/hosts.js:35:15)
#27 11.15     at RWRouter.get text (/app/node_modules/@redwoodjs/structure/dist/ide.js:241:22)
#27 11.15     at Object.getterCommon (/app/node_modules/lazy-get-decorator/common.js:23:32)
#27 11.15     at RWRouter.get (/app/node_modules/lazy-get-decorator/legacy.js:19:29)
#27 11.15     at RWRouter.get sf (/app/node_modules/@redwoodjs/structure/dist/ide.js:253:21)
#27 11.15     at Object.getterCommon (/app/node_modules/lazy-get-decorator/common.js:23:32)
#27 11.15     at RWRouter.get (/app/node_modules/lazy-get-decorator/legacy.js:19:29)
#27 11.15     at RWRouter.get jsxNode (/app/node_modules/@redwoodjs/structure/dist/model/RWRouter.js:86:48) {
#27 11.15   code: 'ERR_INVALID_ARG_TYPE'
#27 11.15 }

finalight avatar Sep 19 '22 03:09 finalight

Hi @finalight thanks for letting us know. I have reproduced the issue and working on a fix. Thanks for your patiences while we resolve and also from using RedwoodJS.

dthyresson avatar Sep 19 '22 18:09 dthyresson