Netlify功能,找不到模块,构建失败

时间:2019-05-31 12:44:09

标签: gatsby netlify

我正在尝试将功能部署到Netlify。我已经在本地用

进行了测试
netlify dev

,一切按预期进行。创建函数时,我使用了

netlify functions:create --name submit-contact

并选择

Send email with no STMP server via 'sendmail' pkg

样板。在本地,一切正常。我注意到它在我的package.json目录中创建了一个嵌套的.netlify/functions/submit-contact文件。我的目录结构是

./.netlify/functions/submit-contact
├── node_modules
├── package-lock.json
├── package.json
├── submit-contact.js
└── validations.js

我的嵌套(非根用户)package.json

{
  "dependencies": {
    "nodemailer": "^6.2.1"
  }
}

但是,部署时,构建失败或功能失败并显示

Could not find "nodemailer" module in file

nodemailer是我唯一的依赖项。我发现一个forum post似乎可以描述我的问题。

我已经将build命令修改为我认为应该可以使用的命令,但是它似乎并没有安装我的dep并继续失败。这是我的构建命令

"build": "cd .netlify/functions/submit-contact && npm install && cd ../../../ && gatsby build"

这是我的部署日志:

8:39:13 PM: Build ready to start
8:39:15 PM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
8:39:15 PM: build-image tag: v3.3.2
8:39:15 PM: buildbot version: 75cd99f62ada9e21edea53208e8baf0eab85a045
8:39:15 PM: Fetching cached dependencies
8:39:15 PM: Starting to download cache of 158.7MB
8:39:16 PM: Finished downloading cache in 593.921286ms
8:39:16 PM: Starting to extract cache
8:39:22 PM: Finished extracting cache in 6.577648977s
8:39:22 PM: Finished fetching cache in 7.237900968s
8:39:22 PM: Starting to prepare the repo for build
8:39:23 PM: Preparing Git Reference refs/heads/master
8:39:24 PM: Found netlify.toml. Overriding site configuration
8:39:24 PM: Different functions path detected, going to use the one specified in the toml file: '.netlify/functions' versus '' in the site
8:39:24 PM: Creating functions prep folder
8:39:24 PM: Starting build script
8:39:24 PM: Installing dependencies
8:39:26 PM: Started restoring cached node version
8:39:28 PM: Finished restoring cached node version
8:39:28 PM: v10.16.0 is already installed.
8:39:29 PM: Now using node v10.16.0 (npm v6.9.0)
8:39:30 PM: Attempting ruby version 2.6.2, read from environment
8:39:31 PM: Using ruby version 2.6.2
8:39:32 PM: Using PHP version 5.6
8:39:32 PM: Started restoring cached node modules
8:39:32 PM: Finished restoring cached node modules
8:39:32 PM: Installing NPM modules using NPM version 6.9.0
8:39:47 PM: npm
8:39:47 PM:  WARN ts-pnp@1.1.2 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
8:39:47 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.8 (node_modules/fsevents):
8:39:47 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
8:39:47 PM: removed 1 package and audited 36486 packages in 13.66s
8:39:47 PM: found 0 vulnerabilities
8:39:47 PM: NPM modules installed
8:39:47 PM: Started restoring cached go cache
8:39:47 PM: Finished restoring cached go cache
8:39:47 PM: unset GOOS;
8:39:47 PM: unset GOARCH;
8:39:47 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
8:39:47 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
8:39:47 PM: go version >&2;
8:39:47 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
8:39:47 PM: go version go1.12 linux/amd64
8:39:47 PM: Installing missing commands
8:39:47 PM: Verify run directory
8:39:47 PM: Executing user command: gatsby build
8:39:50 PM: success open and validate gatsby-configs — 0.006 s
8:39:51 PM: success load plugins — 1.536 s
8:39:51 PM: success onPreInit — 0.006 s
8:39:51 PM: success delete html and css files from previous builds — 0.005 s
8:39:51 PM: success initialize cache — 0.007 s
8:39:51 PM: success copy gatsby files — 0.021 s
8:39:52 PM: success onPreBootstrap — 0.292 s
8:39:54 PM: success loading DatoCMS content — 2.508 s
8:39:54 PM: success source and transform nodes — 2.645 s
8:39:56 PM: success building schema — 1.315 s
8:39:56 PM: success createPages — 0.191 s
8:39:56 PM: success createPagesStatefully — 0.025 s
8:39:56 PM: success onPreExtractQueries — 0.004 s
8:39:56 PM: success update schema — 0.057 s
8:39:56 PM: success extract queries from components — 0.302 s
8:39:57 PM: success run static queries — 1.197 s — 7/7 5.86 queries/second
8:39:59 PM: success run page queries — 2.056 s — 44/44 21.41 queries/second
8:39:59 PM: success write out page data — 0.005 s
8:39:59 PM: success write out redirect data — 0.001 s
8:40:00 PM: success Build manifest and related icons — 0.926 s
8:40:00 PM: success onPostBootstrap — 0.928 s
8:40:00 PM: info bootstrap finished - 13.239 s
8:40:13 PM: success Building production JavaScript and CSS bundles — 12.787 s
8:40:17 PM: success Building static HTML for pages — 4.170 s — 44/44 41.85 pages/second
8:40:17 PM: Generated public/sw.js, which will precache 14 files, totaling 362103 bytes.
8:40:17 PM: info Done building in 30.3 sec
8:40:18 PM: Function Dir: /opt/build/repo/.netlify/functions
8:40:18 PM: TempDir: /tmp/zisi-475981292
8:40:19 PM: Prepping functions with zip-it-and-ship-it 0.3.1
8:40:20 PM: Error: Could not find "nodemailer" module in file: /submit-contact/submit-contact.js.
8:40:20 PM: Please ensure "nodemailer" is installed in the project.
8:40:20 PM: Error prepping functions
8:40:20 PM: Error running command: Build script returned non-zero exit code: 1
8:40:20 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
8:40:20 PM: Failing build: Failed to build site
8:40:20 PM: Finished processing build request in 1m4.869352847s
8:40:20 PM: Shutting down logging, 0 messages pending

0 个答案:

没有答案