Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators don't work if the api folder is missing #1550

Closed
bennettrogers opened this issue Dec 5, 2020 · 6 comments · Fixed by #1553
Closed

Generators don't work if the api folder is missing #1550

bennettrogers opened this issue Dec 5, 2020 · 6 comments · Fixed by #1553
Labels
bug/confirmed We have confirmed this is a bug

Comments

@bennettrogers
Copy link
Contributor

I'm trying to start a new Redwood project that won't need the API side. Following the cookbook, I've deleted the /api folder and re-run yarn install. Now when running any generator command I get:

Error: ENOENT: no such file or directory, scandir '{projectdir}/api/src/functions'

Running Redwood without the api side has worked in the past.

For now I can work around it by just not using the generators, and instead manually creating pages/components/etc.

@Tobbe
Copy link
Member

Tobbe commented Dec 5, 2020

@bennettrogers Could you please provide the output of yarn rw info? Thanks! 🙂

@bennettrogers
Copy link
Contributor Author

Yep, here you go. This is in a clean project where all I've run is:

$ yarn create redwood-app test
$ rm -rf test/api

Info:

yarn run v1.22.4
$ /Users/bennett/workspace/repos/test/node_modules/.bin/rw info

  System:
    OS: macOS 10.15.7
    Shell: 5.0.18 - /usr/local/bin/bash
  Binaries:
    Node: 14.6.0 - /var/folders/60/chchtjcx4gj3cc0wfch2tbcc0000gn/T/yarn--1607177040284-0.16604009507389073/node
    Yarn: 1.22.4 - /var/folders/60/chchtjcx4gj3cc0wfch2tbcc0000gn/T/yarn--1607177040284-0.16604009507389073/yarn
  Databases:
    SQLite: 3.28.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 87.0.4280.88
    Firefox: 83.0
    Safari: 14.0.1
  npmPackages:
    @redwoodjs/core: ^0.21.0 => 0.21.0

✨  Done in 4.58s.

Thanks!

@Tobbe
Copy link
Member

Tobbe commented Dec 5, 2020

I can confirm I'm seeing the same thing

tobbe@XPS9550 MINGW64 ~/dev/redwood/noapi
$ yarn rw info
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\noapi\node_modules\.bin\rw info

  System:
    OS: Windows 10 10.0.19041
  Binaries:
    Node: 14.4.0 - ~\AppData\Local\Temp\yarn--1607190641000-0.5661695207406714\node.CMD
    Yarn: 1.22.4 - ~\AppData\Local\Temp\yarn--1607190641000-0.5661695207406714\yarn.CMD
  Browsers:
    Chrome: 87.0.4280.88
    Edge: Spartan (44.19041.423.0), Chromium (87.0.664.55)
  npmPackages:
    @redwoodjs/core: ^0.21.0 => 0.21.0

Done in 4.34s.

tobbe@XPS9550 MINGW64 ~/dev/redwood/noapi
$ mv api _api

tobbe@XPS9550 MINGW64 ~/dev/redwood/noapi
$ yarn rw g page NewPage
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\noapi\node_modules\.bin\rw g page NewPage
C:\Users\tobbe\dev\redwood\noapi\node_modules\@redwoodjs\cli\node_modules\yargs\build\index.cjs:2756
                throw err;
                ^

Error: ENOENT: no such file or directory, scandir 'C:\Users\tobbe\dev\redwood\noapi\api\src\functions'
    at Object.readdirSync (fs.js:974:3)
    at Object.<anonymous> (C:\Users\tobbe\dev\redwood\noapi\node_modules\@redwoodjs\cli\dist\commands\generate\deploy\providers\aws_serverless.js:60:46)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at Object.require (internal/modules/cjs/helpers.js:73:18)
    at C:\Users\tobbe\dev\redwood\noapi\node_modules\require-directory\index.js:76:17
    at Array.forEach (<anonymous>) {
  errno: -4058,
  syscall: 'scandir',
  code: 'ENOENT',
  path: 'C:\\Users\\tobbe\\dev\\redwood\\noapi\\api\\src\\functions'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

tobbe@XPS9550 MINGW64 ~/dev/redwood/noapi
$

@Tobbe Tobbe added the bug/confirmed We have confirmed this is a bug label Dec 5, 2020
@Tobbe
Copy link
Member

Tobbe commented Dec 5, 2020

So this is the offending line

.readdirSync(path.resolve(getPaths().api.functions))

That whole section should probably be made optional and only printed if there actually are any functions

functions:
${fs
.readdirSync(path.resolve(getPaths().api.functions))
.map((file) => {
const basename = path.basename(file, '.js')
return `${basename}:
description: ${basename} function deployed on AWS Lambda
package:
artifact: api/dist/zipball/${basename}.zip # This is the default location of the zip file generated during the deploy command.
memorySize: 1024 # mb
timeout: 25 # seconds (max: 29)
tags: # Tags for this specific lambda function
endpoint: ${config.web.apiProxyPath}/${basename}
# Uncomment this section to add environment variables either from the serverless dotenv plugin or using serverless params
# environment:
# YOUR_FIRST_ENV_VARIABLE: \${env:YOUR_FIRST_ENV_VARIABLE}
handler: ${basename}.handler
events:
- httpApi:
path: ${config.web.apiProxyPath}/${basename}
method: GET
- httpApi:
path: ${config.web.apiProxyPath}/${basename}
method: POST
`
})
.join(' ')}

@Tobbe
Copy link
Member

Tobbe commented Dec 5, 2020

@bennettrogers You wanna try to submit a PR to fix it?

@bennettrogers
Copy link
Contributor Author

PR submitted: #1553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants