now-cli部署不会建立package.json依赖项 [英] now-cli deployment doesn't build package.json dependencies

查看:175
本文介绍了now-cli部署不会建立package.json依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下方式部署Sapper构建的应用程序 @now-node.任务基本上是部署具有依赖项的Polka服务器,并静态地为static/和client/文件提供服务.我已经设法通过includeFiles包含Lambda所需的文件,但是现在我在日志中看到该构建器忽略package.json中描述的依赖项.确切的消息是

I'm trying to deploy a Sapper built application via @now-node. The task is basically to deploy a Polka server with dependencies and to serve static/ and client/ files statically. I have managed to include the files that Lambda requires via includeFiles but now I see in the logs that the builder ignores dependencies described in package.json. The exact message is

Starting server on port 3000
Cannot find module 'sirv'
Did you forget to add it to "dependencies" in `package.json`?

但是我在构建日志中看到没有收集依赖项. package.jsonpackage-lock.json都存在于源文件中.

But I see in the build log that dependencies are not collected. Both package.json and package-lock.json are present in the source files.

对于如何解决此问题,我将不胜感激.

I'd appreciate any advice on how to approach this.

我到达的now.json配置看起来像这样:

The now.json config I arrived at looks like this:

{
    "version": 2,
    "name": "experimental-sapper",
    "builds": [
        {
            "src": "__sapper__/build/index.js",
            "use": "@now/node",
            "config": {
                "includeFiles": [
                    "../build/**",
                    "../../static/**"
                    ]
            }
        },
        {
            "src": "static/**",
            "use": "@now/static"
        },
        {
            "src": "__sapper__/build/client/**",
            "use": "@now/static"
        }
    ],
    "routes": [
        { "src": "/(.*(\\.css)|(\\.json)|(\\.png))", "dest": "/static/$1" },
        { "src": "/client/(.*)", "dest": "/__sapper__/build/client/$1" },
        { "src": "/(.*)", "dest": "/__sapper__/build/index.js" }
    ],
    "alias": "..."
}

并且src/server.js看起来像这样(在汇总捆绑之前):

And the src/server.js looks like this (before Rollup bundling):

import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import * as sapper from '@sapper/server';
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';
const app = polka() // You can also use Express
    .use(compression({ threshold: 0 }));
if (dev) {
    app.use(sirv('static', { dev }));
}
app.use(sapper.middleware())
    .listen(PORT, err => {
        if (err) console.log('error', err);
    });
export default app.handler;

然后package.json也很标准:

Then package.json is pretty standard as well:

  "description": "TODO",
  "version": "0.0.1",
  "scripts": {
    "dev": "sapper dev",
    "build": "sapper build --legacy",
    "export": "sapper export --legacy",
    "start": "node __sapper__/build",
    "cy:run": "cypress run",
    "cy:open": "cypress open",
    "test": "run-p --race dev cy:run"
  },
  "dependencies": {
    "compression": "^1.7.1",
    "express": "^4.17.1",
    "polka": "^0.5.0",
    "postcss-define-property": "^0.5.0",
    "sirv": "^0.4.0"
  },
  "devDependencies": {
    ...
  },
  "browserslist": "last 2 versions"
}

提前谢谢!

推荐答案

对于遇到此问题的任何人,解决方案是在

For anybody coming across this question, the solution is to use the now-sapper builder at https://www.npmjs.com/package/now-sapper

该站点上有说明,但是本质上您需要如上所述导出您的处理程序,然后让构建器完成其余工作.到目前为止,有一些复杂之处,这意味着仅节点构建器将无法正常工作.

There are instructions on the site, but essentially you need to export your handler as mentioned above, then let the builder do the rest. There are a few intricacies to now which mean that the node builder alone won't work.

您现在的配置应如下所示:

Your now configuration should look like:

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "now-sapper"
    }
  ]
}

从README链接了一个演示项目,这是一个基本的Sapper模板,具有现在所需的配置.

There is a demo project linked from the README which is a basic Sapper template with the required now configuration.

对于导出的应用程序请注意,@now/static就足够了.

Note for exported applications, @now/static will suffice.

这篇关于now-cli部署不会建立package.json依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆