Coder Social home page Coder Social logo

create-react-app-lambda's Introduction

Create-React-App-Lambda

This project is a reference demo showing you how to use Create React App v3 and netlify-lambda v1 together in a Netlify Dev workflow. You can clone this and immediately be productive with a React app with serverless Netlify Functions in the same repo. Alternatively you can deploy straight to Netlify with this one-click Deploy:

Deploy to Netlify

โš ๏ธNOTE: You may not need this project at all. Netlify Dev works with create-react-app out of the box! Only use netlify-lambda if you need a build step for your functions, eg if you want to use Babel or TypeScript (see its README for details).

Project Setup

Source: The main addition to base Create-React-App is a new folder: src/lambda. This folder is specified and can be changed in the package.json script: "build:lambda": "netlify-lambda build src/lambda".

Dist: Each JavaScript file in there will be built for Netlify Function deployment in /built-lambda, specified in netlify.toml.

As an example, we've included a small src/lambda/hello.js function, which will be deployed to /.netlify/functions/hello. We've also included an async lambda example using async/await syntax in async-dadjoke.js.

Video

Learn how to set this up yourself (and why everything is the way it is) from scratch in a video: https://www.youtube.com/watch?v=3ldSM98nCHI

Babel/webpack compilation

All functions (inside src/lambda) are compiled with webpack using Babel, so you can use modern JavaScript, import npm modules, etc., without any extra setup.

Local Development

## prep steps for first time users
npm i -g netlify-cli # Make sure you have the [Netlify CLI](https://github.com/netlify/cli) installed
git clone https://github.com/netlify/create-react-app-lambda ## clone this repo
cd create-react-app-lambda ## change into this repo
yarn # install all dependencies

## done every time you start up this project
ntl dev ## nice shortcut for `netlify dev`, starts up create-react-app AND a local Node.js server for your Netlify functions

This fires up Netlify Dev, which:

  • Detects that you are running a create-react-app project and runs the npm script that contains react-scripts start, which in this project is the start script
  • Detects that you use netlify-lambda as a function builder, and runs the npm script that contains netlify-lambda build, which in this project is the build:lambda script.

You can view the project locally via Netlify Dev, via localhost:8888.

Each function will be available at the same port as well:

  • http://localhost:8888/.netlify/functions/hello and
  • http://localhost:8888/.netlify/functions/async-dadjoke

Deployment

During deployment, this project is configured, inside netlify.toml to run the build command: yarn build.

yarn build corresponds to the npm script build, which uses npm-run-all (aka run-p) to concurrently run "build:app" (aka react-scripts build) and build:lambda (aka netlify-lambda build src/lambda).

Typescript

Click for instructions

You can use Typescript in both your frontend React code (with react-scripts v2.1+) and your serverless functions (with netlify-lambda v1.1+). Follow these instructions:

  1. yarn add -D typescript @types/node @types/react @types/react-dom @babel/preset-typescript @types/aws-lambda
  2. convert src/lambda/hello.js to src/lambda/hello.ts
  3. use types in your event handler:
import { Handler, Context, Callback, APIGatewayEvent } from 'aws-lambda'

interface HelloResponse {
  statusCode: number
  body: string
}

const handler: Handler = (event: APIGatewayEvent, context: Context, callback: Callback) => {
  const params = event.queryStringParameters
  const response: HelloResponse = {
    statusCode: 200,
    body: JSON.stringify({
      msg: `Hello world ${Math.floor(Math.random() * 10)}`,
      params,
    }),
  }

  callback(undefined, response)
}

export { handler }

rerun and see it work!

You are free to set up your tsconfig.json and tslint as you see fit.

If you want to try working in Typescript on the client and lambda side: There are a bunch of small setup details to get right. Check https://github.com/sw-yx/create-react-app-lambda-typescript for a working starter.

Routing and authentication with Netlify Identity

For a full demo of routing and authentication, check this branch: #18 This example will not be maintained but may be helpful.

Service Worker

create-react-app's default service worker (in src/index.js) does not work with lambda functions out of the box. It prevents calling the function and returns the app itself instead (Read more). To solve this you have to eject and enhance the service worker configuration in the webpack config. Whitelist the path of your lambda function and you are good to go.

create-react-app-lambda's People

Contributors

bobwhitelock avatar darthostrich avatar donavon avatar gezquinndesign avatar hidde-vb avatar itaisteinherz avatar kylemcd avatar lgraubner avatar oarnarsson avatar stevenjchang avatar swyxio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-react-app-lambda's Issues

Can't build:lambda once ejected

Hey guys,

When ejecting the app and do nothing else than that, then yarn build:lambda won't work. It throws the following error:

Error: Cannot find module '@babel/plugin-transform-object-assign'

When I install the missing module @babel/plugin-transform-object-assign and then build again it throws:

ERROR in ./subscribe.js
Module build failed (from D:/Documents/web/git/lambda_mailchimp/node_modules/babel-loader/lib/index.js):
Error: [BABEL] D:\Documents\web\git\lambda_mailchimp\src\lambda\subscribe.js: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: undefined. (While processing: "D:\\Documents\\web\\git\\lambda_mailchimp\\node_modules\\babel-preset-react-app\\index.js")
    at module.exports (D:\Documents\web\git\lambda_mailchimp\node_modules\babel-preset-react-app\create.js:48:11)
    at module.exports (D:\Documents\web\git\lambda_mailchimp\node_modules\babel-preset-react-app\index.js:19:10)
    at loadDescriptor (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\full.js:165:14)
    at cachedFunction (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\caching.js:33:19)
    at loadPresetDescriptor (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\full.js:235:63)
    at config.presets.reduce (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\full.js:77:21)
    at Array.reduce (<anonymous>)
    at recurseDescriptors (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\full.js:74:38)
    at loadFullConfig (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\config\full.js:108:6)
    at process.nextTick (D:\Documents\web\git\lambda_mailchimp\node_modules\@babel\core\lib\transform.js:28:33)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
Done in 2.87s.

I am using Windows 10.

Any ideas why this is happening?

Cheers

Neither of the buttons work

Clicking either button doesn't send a response. I think the issue is that on the front end it can't find the lambda functions at '/.netlify/functions/' but I can't figure out why

Unable to start

Hey ๐Ÿ‘‹

I'm not able to get this to run properly. The React App runs fine, but seems the netlify lambda is not working.

Steps to reproduce:

  1. Clone this repo
  2. Run yarn
  3. Run yarn start

When I do yarn start the CRA app launches. I click on the Call Lambda button and:
image

This is the error I get if I do yarn start:lambda directly:
image

I also tried running yarn build:lambda but get this:

ERROR in ./hello.js
Module build failed (from /Users/peduarte/Projects/playground/create-react-app-lambda/node_modules/babel-loader/lib/index.js):
Error: Cannot find module '@babel/plugin-transform-object-assign' from '/Users/peduarte/Projects/playground/create-react-app-lambda'

Could be related to this... dominictarr/event-stream#115 ? ๐Ÿค”

Im not sure what's going on, would appreciate any guidance ๐Ÿ™

Thanks ๐Ÿ‘Š

Instructions are conflicting and out of date

The readme and various instructions are conflicting.

  • When you google "netflify lambda create react app" this repo and instructional videos pointing to it are the first results.

  • The .setupProxy.js file is missing from the repo.

  • In the history, you can find a note about why it was deleted; and comment about updated instructions.

  • link to commit and notes when was deleted: eb77fe8

  • link to notes about updated method and readme: #30

  • However, there are no complete instructions about how to run it without it, and a repo does not work automatically when removed ; nor when you change the url, per the readme.

  • Link above says that readme used to be out of date, but video in readme is the same out of date video.

  • Can someone please clarify/ update the instructions.

  • current docs also point to this repo and video https://functions.netlify.com/example/create-react-app-lambda/

Getting Error with fresh clone: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

With a fresh clone of this repo I get an error message when running yarn start:lambda src/lambda and making a request to localhost:9000. Attaching my yarn.lock as well.
yarn.lock.txt

OS: MacOS 10.13.6
Yarn: 1.10.1
Node: v10.12.0

Error does not happen until I make a request.

โžœ  labs rm -rf create-react-app-lambda 
โžœ  labs git clone https://github.com/netlify/create-react-app-lambda.git
Cloning into 'create-react-app-lambda'...
remote: Enumerating objects: 69, done.
remote: Counting objects: 100% (69/69), done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 118 (delta 32), reused 43 (delta 17), pack-reused 49
Receiving objects: 100% (118/118), 308.19 KiB | 1.10 MiB/s, done.
Resolving deltas: 100% (49/49), done.
โžœ  labs cd create-react-app-lambda 
โžœ  create-react-app-lambda git:(master) yarn
yarn install v1.10.1
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
warning " > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
warning " > [email protected]" has unmet peer dependency "webpack@>=2".
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
โœจ  Done in 18.28s.
โžœ  create-react-app-lambda git:(master) โœ— yarn start:lambda src/lambda
yarn run v1.10.1
$ netlify-lambda serve src/lambda src/lambda
netlify-lambda: Starting server
Lambda server is listening on 9000
Hash: 6f04e8584e1f186c9788
Version: webpack 4.20.2
Time: 1353ms
Built at: 10/23/2018 4:08:09 PM
   Asset      Size  Chunks             Chunk Names
hello.js  1.62 KiB       0  [emitted]  hello
Entrypoint hello = hello.js
[0] ./hello.js 1020 bytes {0} [built]
Request from ::1: GET /
Response with status 500 in 5 ms.
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.join (path.js:1155:7)
    at /Users/jakehow/projects/labs/create-react-app-lambda/node_modules/netlify-lambda/lib/serve.js:51:23
    at Layer.handle [as handle_request] (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:137:13)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:131:14)
    at Route.dispatch (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/layer.js:95:5)
    at /Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/index.js:281:22
    at param (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/index.js:354:14)
    at param (/Users/jakehow/projects/labs/create-react-app-lambda/node_modules/express/lib/router/index.js:365:14)

Unable to deploy; Error while deploying functions

Hi,
I forked a repo at https://github.com/bestpricedin/create-react-app-lambda, changed babel-loader version as "babel-loader": "8.0.5", using yarn.
I am using netlify-cli to run this locally and it works.
When I deploy to netlify, I get following error. Can you please help me solve the error?
My netlify -v is netlify-cli/2.11.14 darwin-x64 node-v8.15.0

12:55:51 PM: Starting to prepare functions from 'build'
12:55:51 PM: Zipping functions from /opt/build/repo/built-lambda to /tmp/zisi-889841717
12:55:52 PM: Error: Could not find "encoding" module in file: /repo/built-lambda/async-dadjoke.js. 
         
Please ensure "encoding" is installed in the project.
12:55:52 PM: Failing build: Failed to prepare functions for deployment
12:55:52 PM: failed during stage 'preparing functions for deployment': exit status 1
12:55:52 PM: Finished processing build request in 54.037857466s
12:55:52 PM: Shutting down logging, 0 messages pending

babel-loader

### babel-loader is rekt @sw-yx lets GOOOOOO


There might be a problem with the project dependency tree.

It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "babel-loader": "8.0.5"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:

  /Users/asdf/coding/personal/contact-site/create-react-app-lambda/node_modules/babel-loader (version: 8.0.6) 

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /Users/asdf/coding/personal/contact-site/create-react-app-lambda/node_modules/babel-loader is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls babel-loader in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed babel-loader.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
โ—ˆ "yarn start" exited with code 1. Shutting down Netlify Dev server

Service worker prevents function calls

As the service worker seems to be the "official" one I assume it can't be used like this in combination with functions.

facebook/create-react-app#2237 (comment)

The Service worker will just return the app instead of the function itself. Only option is ejecting and extend navigateFallbackWhitelist option.

I didn't test this with this package, but with a bare CRA app and functions which should be basically the same.

error: lambda functions are not working in localhost

Steps to repeat error:

  • download repo to desktop
  • npm install
  • in one terminal: npm run start
  • on another terminal npm run start:lambda

in the browser, at localhost 3000, press the buttons to call the lambda functions:

  • error in console: VM271:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

  • in browser url http://localhost:9000/.netlify/functions/hello responds with hello world.

  • in browser url http://localhost:9000/.netlify/functions/async-dadjoke responds with {"msg":"Request failed with status code 503"} (think that's expected).

Cannot get proxy working locally.

Hello,

Trying to use this to run Stripe Elements with a local React site but can't get the proxy to work.

Was following this example but updated as per the code examples in this repo to use yarn: https://mitchgavan.com/react-serverless-shop/

Getting this error:
[HPM] Error occurred while trying to proxy request /charge from localhost:3000 to https://localhost:9000 (EPROTO) (https://nodejs.org/api/errors.html#errors_common_system_errors)

There's nothing else on port 9000. I've tried restarting both the app and lambda server and still cannot connect.

It's similar to this: #19

However none of the solutions there worked.

When I hit Submit on my Stripe checkout form, the proxy fails and I cannot complete any transactions (running with test API keys). Is there anything specific to look for to see why the proxy is failing?

[security] Enforce Branch Protections

This is an issue generated by (for-internal-use-only)github-tools

Description

This repository has exceeded the development grace period, and the repo owner must decide if branch protections should be enforced.
If this repository houses code used in production in any capacity, branch protections must be enforced. Read (for-internal-use-only)here for more details

What do I need to do?

  • You can control whether or not branch protections are enforced by exclusively creating either of the labels:
    'enforce-branch-protections: true' or 'enforce-branch-protections: false'
  • If there is no branch protection control label, this issue will be recreated.
  • Once you have created either label, you can close this issue.
  • If you have issues or questions, please reach out to #internal-security-n-compliance on slack.

Functions are not called on localhost

I tried to run this locally. Here are the related steps ([...] means "omitted"):

$ ntl help
[...]
VERSION
  netlify-cli/2.12.0 linux-x64 node-v10.16.3
[...]
$ yarn -v
1.17.3

$ gcl [email protected]:netlify/create-react-app-lambda.git
$ cd create-react-app-lambda

$ yarn
[...]

$ ntl dev

I can confirm that calls to

http://localhost:8888/.netlify/functions/hello and
http://localhost:8888/.netlify/functions/async-dadjoke

work as expected, but clicking the buttons on the client (http://localhost:3000) causes them stuck in "Loading..." state, whereas in the console there is an error message:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

(the response to the API call from the click handler being the content of index.html).

At the same time, the instance deployed to Netlify works fine (clicking the buttons yields the expected text underneath).

I tried to fiddle around with proxies as in https://www.youtube.com/watch?v=3ldSM98nCHI and the documentation, but did not get the local functions called from the client yet.

Chuck Norris Jokes are inappropriate

I know that the content is out of your control, but you may want to consider using a different free API service other than https://api.chucknorris.io for your examples. Many of the "jokes" are inappropriate, or are in bad taste. I'm assuming that a company such as Netlify doesn't want to be associated with this.

I almost hate posting this, but here's an example:

Whenever Chuck Norris gets a massage, he gives the female masseuse a happy ending.

Couldn't find any versions for "flatmap-stream" that matches "0.1.1"

Running yarn with a newly cloned repo prompts a manual selection for the "event-stream" package and also is unable to find version 0.1.1 for "flatmap-stream".

Console output:

? Please choose a version of "event-stream" from this list: 4.0.1
Couldn't find any versions for "flatmap-stream" that matches "0.1.1"
? Please choose a version of "flatmap-stream" from this list: 0.0.1-security
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/flatmap-stream/-/flatmap-stream-0.1.1.tgz: Request failed \"404 Not Found\"".

Cannot start lambda server

Node version: 10.10 (but also doesn't work on 8.x)
OS: Ubuntu 18.04

Issue happens with either yarn start and yarn start:lambda

> yarn start:lambda                                                                                                                                                 master [98c9fc6] modified
yarn run v1.10.1
$ netlify-lambda serve src/lambda
netlify-lambda: Starting server
Lambda server is listening on 9000
Unhandled rejection Error: Cannot find module '/home/darren/code/create-react-app-lambda/lambda/hello'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.resolve (internal/modules/cjs/helpers.js:30:19)
    at Object.clearCache (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/lib/serve.js:105:36)
    at /home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/bin/cmd.js:35:16
    at Array.forEach (<anonymous>)
    at Watching.handler (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/bin/cmd.js:34:32)
    at compiler.hooks.done.callAsync (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:100:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/darren/code/create-react-app-lambda/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/darren/code/create-react-app-lambda/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:99:28)
    at onCompiled (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:47:18)
    at hooks.afterCompile.callAsync.err (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/node_modules/webpack/lib/Compiler.js:547:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/darren/code/create-react-app-lambda/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/darren/code/create-react-app-lambda/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/home/darren/code/create-react-app-lambda/node_modules/netlify-lambda/node_modules/webpack/lib/Compiler.js:544:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/darren/code/create-react-app-lambda/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)

useProxy.js not working - new code provided

Please use the following code:

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(createProxyMiddleware('/.netlify/functions/', {
    target: 'http://localhost:9000/',
    "pathRewrite": {
      "^/\\.netlify/functions": ""
    }
  }));
};

Throws error about missing yarn

I don't have yarn installed, so I tried using npm instead.

npm i -g netlify-cli # Make sure you have the [Netlify CLI](https://github.com/netlify/cli) installed
git clone https://github.com/netlify/create-react-app-lambda ## clone this repo
cd create-react-app-lambda ## change into this repo
npm install # install all dependencies

All of the above commands runs just fine. But then, when I try to run ntl dev, I get this output

$ ntl dev
โ—ˆ Netlify Dev โ—ˆ
โ—ˆ Starting Netlify Dev with create-react-app
โ—ˆ Function builder netlify-lambda detected: Running npm script build:lambda
 ยป   Warning: โ—ˆ This is a beta feature, please give us feedback on how to
 ยป   improve at https://github.com/netlify/cli/
'yarn' is not recognized as an internal or external command,
operable program or batch file.
{ Error: spawn yarn ENOENT
    at notFoundError (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:239:12)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn yarn',
  path: 'yarn',
  spawnargs: [ 'start' ] }
{ Error: spawn yarn ENOENT
    at notFoundError (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:239:12)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn yarn',
  path: 'yarn',
  spawnargs: [ 'start' ] }

C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:116
      throw ex;
      ^
abort({"code":"ENOENT","errno":"ENOENT","syscall":"spawn yarn","path":"yarn","spawnargs":["start"]}) at Error
    at jsStackTrace (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:1070:13)
    at stackTrace (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:1087:12)
    at process.abort (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:8415:44)
    at process.emit (events.js:182:13)
    at processEmit [as emit] (C:\Users\tobbe\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\signal-exit\index.js:155:32)
    at emitPromiseRejectionWarnings (internal/process/promises.js:105:20)
    at process._tickCallback (internal/process/next_tick.js:69:34)

Removing yarn.lock fixes the issue and makes everything run fine on localhost. Since I'm not using yarn locally, I also updated netlify.toml to use npm instead of yarn for building on netlify's servers.

Took a while to figure out why it wasn't working. (Having not worked with Netlify Dev before it wasn't exactly obvious that your lockfile determines what tools it tries to use ๐Ÿ˜‰)

I guess this issue is semi-related too: netlify/cli#328

Anyway. I suggest removing yarn.lock from the repo and instead be more specific about exactly what package versions to use in package.json. Alternatively you could document that yarn needs to be installed for this to work, and why, and ways to work around it.

Error occured while trying to proxy to: localhost:3000/hello

i cannot seem to get it to work.
clean install, both with npm and yarn.

bad gateway 504 on all api calls
[HPM] Error occurred while trying to proxy request /hello from localhost:3000 to http://localhost:9000/ (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
node 10.15.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.