now-cli deployment doesn't build package.json dependencies

巧了我就是萌 提交于 2019-12-22 18:48:14

问题


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`?

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.

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": "..."
}

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;

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"
}

Thanks in advance!

来源:https://stackoverflow.com/questions/56460903/now-cli-deployment-doesnt-build-package-json-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!