netlify dev 开始无限循环

iam*_*kok 5 javascript lambda amazon-web-services gatsby netlify

我正在努力添加环境变量来为 Netlify 函数进行条件切换。当我运行时,CONTEXT=development netlify dev我陷入了无限循环,并且 Lambda 服务器不断切换端口。

\n\n

AWS 函数package.json.

\n\n
yarn develop\nyarn run v1.12.3\n$ CONTEXT=development netlify dev\n\xe2\x97\x88 Netlify Dev \xe2\x97\x88\n\xe2\x97\x88 Injected build setting env var:  GATSBY_DEV_GITHUB_CLIENT_ID\n\xe2\x97\x88 Injected build setting env var:  GATSBY_DEV_GITHUB_CLIENT_SECRET\n\xe2\x97\x88 Injected build setting env var:  GATSBY_DEV_HOST_URL\n\xe2\x97\x88 Injected build setting env var:  GATSBY_FUNCTION_PASSWORD\n\xe2\x97\x88 Injected build setting env var:  GATSBY_GITHUB_CLIENT_ID\n\xe2\x97\x88 Injected build setting env var:  GATSBY_GITHUB_CLIENT_SECRET\n\xe2\x97\x88 Injected build setting env var:  GATSBY_HOST_URL\n\xe2\x97\x88 Injected build setting env var:  GATSBY_DEV_FUNCTION_PASSWORD\n\xe2\x97\x88 Starting Netlify Dev with gatsby\nWaiting for localhost:8000.\n\xe2\x97\x88 Lambda server is listening on 34567\n$ npm run develop\nnpm WARN lifecycle The node binary used for scripts is /var/folders/s7/vtbv89nd3f99nlx5y9h94qk00000gn/T/yarn--1560352104668-0.36838903564793/node but npm is using /Users/skok/.nvm/versions/node/v11.5.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.\n\n> gatsby-dev-blog-starter@0.1.0 develop /Users/skok/dev/gatsby-dev-blog-starter\n> CONTEXT=development netlify dev\n\n.\xe2\x97\x88 Netlify Dev \xe2\x97\x88\n.\xe2\x97\x88 Starting Netlify Dev with gatsby\nWaiting for localhost:8000.\n\xe2\x97\x88 Lambda server is listening on 55396\n$ npm run develop\n.npm WARN lifecycle The node binary used for scripts is /var/folders/s7/vtbv89nd3f99nlx5y9h94qk00000gn/T/yarn--1560352107238-0.9451571250276476/node but npm is using /Users/skok/.nvm/versions/node/v11.5.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.\n\n> gatsby-dev-blog-starter@0.1.0 develop /Users/skok/dev/gatsby-dev-blog-starter\n> CONTEXT=development netlify dev\n\n..\xe2\x97\x88 Netlify Dev \xe2\x97\x88\n.\xe2\x97\x88 Starting Netlify Dev with gatsby\n.Waiting for localhost:8000.\n\xe2\x97\x88 Lambda server is listening on 55412\n$ npm run develop\n.npm WARN lifecycle The node binary used for scripts is /var/folders/s7/vtbv89nd3f99nlx5y9h94qk00000gn/T/yarn--1560352109773-0.46483751576396815/node but npm is using /Users/skok/.nvm/versions/node/v11.5.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.\n\n> gatsby-dev-blog-starter@0.1.0 develop /Users/skok/dev/gatsby-dev-blog-starter\n> CONTEXT=development netlify dev\n\n...\xe2\x97\x88 Netlify Dev \xe2\x97\x88\n.. \xe2\x97\x88 Starting Netlify Dev with gatsby\n.Waiting for localhost:8000.\n\xe2\x97\x88 Lambda server is listening on 55436\n$ npm run develop\n..npm WARN lifecycle The node binary used for scripts is /var/folders/s7/vtbv89nd3f99nlx5y9h94qk00000gn/T/yarn--1560352112263-0.5329314860894214/node but npm is using /Users/skok/.nvm/versions/node/v11.5.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.\n\n> gatsby-dev-blog-starter@0.1.0 develop /Users/skok/dev/gatsby-dev-blog-starter\n> CONTEXT=development netlify dev\n
Run Code Online (Sandbox Code Playgroud)\n\n

Netlify 构建日志

\n\n
8:01:43 AM: Build ready to start\n8:01:52 AM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63\n8:01:52 AM: build-image tag: v3.3.2\n8:01:52 AM: buildbot version: 75cd99f62ada9e21edea53208e8baf0eab85a045\n8:01:52 AM: Fetching cached dependencies\n8:01:52 AM: Starting to download cache of 255.0KB\n8:01:52 AM: Finished downloading cache in 119.733265ms\n8:01:52 AM: Starting to extract cache\n8:01:52 AM: Failed to fetch cache, continuing with build\n8:01:52 AM: Starting to prepare the repo for build\n8:01:53 AM: No cached dependencies found. Cloning fresh repo\n8:01:53 AM: git clone https://github.com/iamskok/gatsby-dev-blog-starter\n8:01:56 AM: Preparing Git Reference refs/heads/master\n8:01:56 AM: Found netlify.toml. Overriding site configuration\n8:01:56 AM: Different publish path detected, going to use the one specified in the toml file: \'public\' versus \'public/\' in the site\n8:01:56 AM: Different build command detected, going to use the one specified in the toml file: \'yarn build\' versus \'CONTEXT=production gatsby build\' in the site\n8:01:56 AM: Different functions path detected, going to use the one specified in the toml file: \'.netlify/functions\' versus \'\' in the site\n8:01:56 AM: Different base path detected, going to use the one specified in the toml file: \'/\' versus \'\' in the site\n8:01:56 AM: Creating functions prep folder\n8:01:56 AM: Starting build script\n8:01:56 AM: Installing dependencies\n8:01:58 AM: Downloading and installing node v11.5.0...\n8:01:58 AM: Downloading https://nodejs.org/dist/v11.5.0/node-v11.5.0-linux-x64.tar.xz...\n8:01:59 AM:   0.1%\n8:01:59 AM: \n##\n8:01:59 AM:   2.9%\n8:01:59 AM: \n###                                                                        4.7%\n8:01:59 AM: \n####\n8:01:59 AM:   5.9%\n8:01:59 AM: \n#####                                                                      7.3%\n8:01:59 AM: #####\n8:01:59 AM:                         8.2%\n8:01:59 AM: \n######\n8:01:59 AM:   9.0%\n8:01:59 AM: \n#######\n8:01:59 AM:                           10.1%\n8:01:59 AM: \n########\n8:01:59 AM:  11.7%\n8:01:59 AM: \n#########\n8:01:59 AM:                13.0%\n8:02:00 AM: \n###########\n8:02:00 AM:                 15.5%\n8:02:00 AM: \n############                                                              1\n8:02:00 AM: 7.0%\n8:02:00 AM: \n############\n8:02:00 AM:         17.9%\n8:02:00 AM: \n#############\n8:02:00 AM:                                   18.4%\n8:02:00 AM: \n##############                                                            20.2%\n8:02:00 AM: \n###############                                                           21.0%\n8:02:01 AM: \n###############\n8:02:01 AM:  21.8%\n8:02:01 AM: \n################\n8:02:01 AM:  22.7%\n8:02:01 AM: \n################\n8:02:01 AM:  23.6%\n8:02:01 AM: \n#################\n8:02:01 AM:  24.4%\n8:02:02 AM: \n#################\n8:02:02 AM:                   24.9%\n8:02:02 AM: \n##################\n8:02:02 AM:  26.3%\n8:02:02 AM: \n###################\n8:02:02 AM:  26.9%\n8:02:02 AM: \n######################\n8:02:02 AM:      30.7%\n8:02:03 AM: \n######################\n8:02:03 AM:      31.0%\n8:02:03 AM: \n#######################\n8:02:03 AM:  32.8%\n8:02:03 AM: \n#######################\n8:02:03 AM:                             33.3%\n8:02:03 AM: \n########################\n8:02:03 AM:                 34.1%\n8:02:04 AM: \n#########################\n8:02:04 AM:  35.2%\n8:02:04 AM: \n###########################                                               38.5%\n8:02:04 AM: \n###########################\n8:02:04 AM:     38.7%\n8:02:04 AM: \n############################\n8:02:04 AM:                                 39.7%\n8:02:04 AM: \n#############################\n8:02:04 AM:          41.0%\n8:02:04 AM: \n##############################\n8:02:04 AM:                                   41.8%\n8:02:04 AM: \n###############################\n8:02:04 AM:                               43.2%\n8:02:04 AM: \n################################\n8:02:04 AM:                      44.7%\n8:02:05 AM: \n################################\n8:02:05 AM:  45.6%\n8:02:05 AM: \n#################################\n8:02:05 AM:           46.4%\n8:02:05 AM: \n##################################\n8:02:05 AM:                  47.5%\n8:02:05 AM: \n##################################\n8:02:05 AM:                       48.5%\n8:02:05 AM: \n###################################\n8:02:05 AM:                               49.4%\n8:02:05 AM: \n####################################\n8:02:05 AM:  50.4%\n8:02:05 AM: \n#####################################                                     51.8%\n8:02:05 AM: \n######################################\n8:02:05 AM:  53.1%\n8:02:05 AM: \n#######################################\n8:02:05 AM:  54.4%\n8:02:06 AM: \n#######################################\n8:02:06 AM:                                54.8%\n8:02:06 AM: \n########################################\n8:02:06 AM:                  56.3%\n8:02:06 AM: \n#########################################\n8:02:06 AM:  57.0%\n8:02:06 AM: \n#########################################\n8:02:06 AM:  57.7%\n8:02:06 AM: \n#########################################\n8:02:06 AM:                58.0%\n8:02:06 AM: \n#########################################                                 5\n8:02:06 AM: 8.2%\n8:02:06 AM: \n##########################################\n8:02:06 AM:  58.6%\n8:02:07 AM: \n##########################################\n8:02:07 AM:  59.4%\n8:02:08 AM: \n##########################################\n8:02:08 AM:          59.5%\n8:02:08 AM: \n##########################################\n8:02:08 AM:      59.5%\n8:02:08 AM: \n##############################################\n8:02:08 AM:      64.0%\n8:02:08 AM: \n###################################################\n8:02:08 AM:    71.0%\n8:02:08 AM: \n###################################################\n8:02:08 AM:                72.0%\n8:02:09 AM: \n####################################################\n8:02:09 AM:       73.0%\n8:02:09 AM: \n#####################################################                     73.7%\n8:02:09 AM: \n#####################################################\n8:02:09 AM:  74.2%\n8:02:09 AM: \n######################################################\n8:02:09 AM:  75.0%\n8:02:09 AM: \n######################################################\n8:02:09 AM:              75.7%\n8:02:09 AM: \n#####################################\n8:02:09 AM: #################                    76.2%\n8:02:10 AM: \n#######################################################\n8:02:10 AM:  77.6%\n8:02:10 AM: \n#######################################################\n8:02:10 AM:  77.7%\n8:02:10 AM: \n#################################################\n8:02:10 AM: #######                  78.1%\n8:02:10 AM: \n########################################################                  78.8%\n8:02:11 AM: #\n8:02:11 AM: ##############################################\n8:02:11 AM: ###########                81.9%\n8:02:11 AM: \n###########################################################               82.4\n8:02:11 AM: %\n8:02:11 AM: \n###########################################################\n8:02:11 AM:  82.8%\n8:02:11 AM: \n############################################################\n8:02:11 AM:  84.7%\n8:02:11 AM: \n#############################################################             85.7%\n8:02:12 AM: \n##############################################################            86.5%\n8:02:12 AM: \n#####################################################\n8:02:12 AM: #########            86.6%\n8:02:12 AM: \n#############################\n8:02:12 AM: ##################################           87.5%\n8:02:12 AM: \n###############################################################           88.1%\n8:02:13 AM: \n###############################################################           88.3%\n8:02:13 AM: \n################################################################\n8:02:13 AM:  89.0%\n8:02:13 AM: \n#############################################################\n8:02:13 AM: ###          89.5%\n8:02:13 AM: \n#################################################################\n8:02:13 AM:  90.9%\n8:02:13 AM: \n##################################################################\n8:02:13 AM:  91.7%\n8:02:13 AM: \n##################################################################        92.5%\n8:02:14 AM: \n###################################################################\n8:02:14 AM:  94.1%\n8:02:14 AM: \n####################################################################\n8:02:14 AM:  94.8%\n8:02:14 AM: \n####################################################################\n8:02:14 AM:  95.6%\n8:02:14 AM: \n#####################################################################\n8:02:14 AM:  96.1%\n8:02:14 AM: \n#####################################################################     96.5%\n8:02:14 AM: \n#####################################################################     97.1%\n8:02:14 AM: \n###################################################\n8:02:14 AM: ###################    97.6%\n8:02:14 AM: \n######################################################################    98.2%\n8:02:14 AM: \n#######################################################################   98.6%\n8:02:15 AM: \n###################################################################\n8:02:15 AM: ####   99.0%\n8:02:15 AM: \n######################################################################\n8:02:15 AM: #   99.8%\n8:02:15 AM: \n########################################################################\n8:02:15 AM: 100.0%\n8:02:15 AM: Computing checksum with sha256sum\n8:02:15 AM: Checksums matched!\n8:02:17 AM: Now using node v11.5.0 (npm v6.4.1)\n8:02:18 AM: Attempting ruby version 2.6.2, read from environment\n8:02:19 AM: Using ruby version 2.6.2\n8:02:19 AM: Using PHP version 5.6\n8:02:19 AM: Started restoring cached node modules\n8:02:19 AM: Finished restoring cached node modules\n8:02:19 AM: Started restoring cached yarn cache\n8:02:19 AM: Finished restoring cached yarn cache\n8:02:19 AM: Installing yarn at version 1.3.2\n8:02:19 AM: Installing Yarn!\n8:02:19 AM: > Downloading tarball...\n8:02:19 AM: [1/2]: https://yarnpkg.com/downloads/1.3\n8:02:19 AM: .2/yarn-v1.3.2.tar.gz --> /tmp/yarn.tar.gz.r76iL9IFsO\n8:02:19 AM:   % Total    % Receiv\n8:02:19 AM: ed % Xferd  Average Speed   Time    Time     Time  Current\n8:02:19 AM:                               Dload  Upload   Total   Spent    Left  Sp\n8:02:19 AM: eed\n8:02:19 AM: \n  0     0    0     0    0     0\n8:02:19 AM:   0      0 --:--:-- --:--:-- --:--:--     0\n8:02:20 AM: \n100    91  100    91    0     0    312      0 --:--:-- --:--:-- --:--:--   313\n8:02:21 AM: \n  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0\n8:02:21 AM: \n100   608    0   608    0     0    487      0 --:--:--  0:00:01 --:--:--  593k\n8:02:21 AM: \n100  865k  100  865k    0     0   514k      0  0:00\n8:02:21 AM: :01  0:00:01 --:--:--  514k\n8:02:21 AM: [2/2]: https://\n8:02:21 AM: yarnpkg.com/downloads/1.3.2/yarn-v1.3.2.tar.gz.asc --> /tmp/yarn.tar.gz.\n8:02:21 AM: r76iL9IFsO.asc\n8:02:21 AM: \n100    95  100    95    0     0   2206      0 --:--:-- --:--:-- --:--:-\n8:02:21 AM: -  2206\n8:02:21 AM: \n  0     0    0     0    0     0      0      0 --:--:--\n8:02:21 AM: --:--:-- --:--:--     0\n100   612    0   612    0     0   3167      0 --:--:-- --:--:-- --:--:--  597k\n8:02:21 AM: \n100  1027  100  1027    0     0   4452      0 --:--:-- --:--:-- --\n8:02:21 AM: :--:--  4452\n8:02:21 AM: > Verifying integrity...\n8:02:21 AM: gpg: Signature made Thu 02 Nov 2017 04:44:10 PM UTC using RSA key ID FD2497F5\n8:02:21 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"\n8:02:21 AM: gpg: Note: This key has expired!\n8:02:21 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B\n8:02:21 AM:  86E5 0310\n8:02:21 AM:      Subkey fingerprint: 6A01 0C51 6600 6599 AA17  F081 46C2 130D FD24 97F5\n8:02:21 AM: > GPG signature looks good\n8:02:21 AM: > Extracting to ~/.yarn...\n8:02:21 AM: > Adding to $PATH...\n8:02:21 AM: > We\'ve added the following to your /opt/buildhome/.profile\n8:02:21 AM: > If this isn\'t the profile of your current shell then please add the following to your correct profile:\n8:02:21 AM: export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"\n8:02:21 AM: \n8:02:22 AM: > Successfully installed Yarn 1.3.2! Please open another terminal where the `yarn` command will now be available.\n8:02:22 AM: Installing NPM modules using Yarn version 1.3.2\n8:02:23 AM: yarn install v1.3.2\n8:02:23 AM: (node:1370) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.\n8:02:23 AM: [1/4] Resolving packages...\n8:02:24 AM: [2/4] Fetching packages...\n8:02:42 AM: info fsevents@1.2.8: The platform "linux" is incompatible with this module.\n8:02:42 AM: info "fsevents@1.2.8" is an optional dependency and failed compatibility check. Excluding it from installation.\n8:02:42 AM: [3/4] Linking dependencies...\n8:02:42 AM: warning "gatsby > pnp-webpack-plugin > ts-pnp@1.1.2" has unmet peer dependency "typescript@*".\n8:02:42 AM: warning "gatsby > mini-css-extract-plugin > schema-utils > ajv-errors@1.0.1" has unmet peer dependency "ajv@>=5.0.0".\n8:02:42 AM: warning " > gatsby-plugin-sass@2.0.11" has unmet peer dependency "node-sass@^4.9.0".\n8:02:42 AM: warning "gatsby-plugin-sass > sass-loader@7.1.0" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".\n8:02:50 AM: [4/4] Building fresh packages...\n8:02:55 AM: Done in 32.09s.\n8:02:55 AM: NPM modules installed using Yarn\n8:02:55 AM: (node:1495) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.\n8:02:56 AM: Started restoring cached go cache\n8:02:56 AM: Finished restoring cached go cache\n8:02:56 AM: unset GOOS;\n8:02:56 AM: unset GOARCH;\n8:02:56 AM: export GOROOT=\'/opt/buildhome/.gimme/versions/go1.12.linux.amd64\';\n8:02:56 AM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";\n8:02:56 AM: go version >&2;\n8:02:56 AM: export GIMME_ENV=\'/opt/buildhome/.gimme/env/go1.12.linux.amd64.env\';\n8:02:56 AM: go version go1.12 linux/amd64\n8:02:56 AM: Installing missing commands\n8:02:56 AM: Verify run directory\n8:02:56 AM: Executing user command: yarn build\n8:02:56 AM: yarn run v1.3.2\n8:02:56 AM: (node:1548) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.\n8:02:56 AM: $ gatsby build\n8:02:59 AM: success open and validate gatsby-configs \xe2\x80\x94 0.034 s\n8:03:00 AM: success load plugins \xe2\x80\x94 0.785 s\n8:03:00 AM: success onPreInit \xe2\x80\x94 0.006 s\n8:03:00 AM: success delete html and css files from previous builds \xe2\x80\x94 0.006 s\n8:03:00 AM: success initialize cache \xe2\x80\x94 0.009 s\n8:03:00 AM: success copy gatsby files \xe2\x80\x94 0.027 s\n8:03:00 AM: success onPreBootstrap \xe2\x80\x94 0.010 s\n8:03:00 AM: success source and transform nodes \xe2\x80\x94 0.172 s\n8:03:00 AM: success building schema \xe2\x80\x94 0.413 s\n8:03:00 AM: success createPages \xe2\x80\x94 0.041 s\n8:03:00 AM: success createPagesStatefully \xe2\x80\x94 0.036 s\n8:03:00 AM: success onPreExtractQueries \xe2\x80\x94 0.003 s\n8:03:00 AM: success update schema \xe2\x80\x94 0.035 s\n8:03:01 AM: success extract queries from components \xe2\x80\x94 0.203 s\n8:03:01 AM: success run static queries \xe2\x80\x94 0.015 s \xe2\x80\x94 4/4 282.72 queries/second\n8:03:07 AM: success run page queries \xe2\x80\x94 6.163 s \xe2\x80\x94 8/8 1.30 queries/second\n8:03:07 AM: success write out page data \xe2\x80\x94 0.004 s\n8:03:07 AM: success write out redirect data \xe2\x80\x94 0.001 s\n8:03:36 AM: success Build manifest and related icons \xe2\x80\x94 0.217 s\n8:03:36 AM: success onPostBootstrap \xe2\x80\x94 0.21

tal*_*ves 2

您正在使用的函数路径是生产中的代理路径 ( /.netlify/functions/)。本地使用 ( netlify dev) netlify 开发工作流程将使用该路径来监视函数的已编译更改。

将functions目录移动到不同的位置(在示例中/src/functions)并更改netlify.tomlbuild.functions =“functions”。Netlify 将使用该目录来获取捆绑的脚本。

使用捆绑命令在工作流程中构建函数。Netlify 有一个名为netlify-lambda您可以使用的 cli ( yarn add netlify-lambda -D)。将构建命令添加到您的构建工作流程中。

$ netlify-lambda build src/functions
Run Code Online (Sandbox Code Playgroud)

无限循环的常见原因netlify dev

以下内容无效,将导致netlify dev不断调用自身函数

  • 将函数的源设置为与构建相同的目录
  • netlify dev命令包含在包scripts.development命令中。(在示例中`“development”:“npm run netlify dev”)

注意:在 Netlify 上使用函数时,您需要将依赖项捆绑到函数中,否则它们在部署时将无法解析。