thgh / vercel-sapper

Vercel builder for Sapper with SSR enabled
MIT License
191 stars 25 forks source link

Don't work by following the readme #38

Closed cybertouchllc closed 4 years ago

cybertouchllc commented 4 years ago

Note: Creating a sapper project from the Dashboard and 0 config, works great, but I think that I cannot make authenticated apps with that approach since that template do sapper export instead of sapper build.

Don't know if that the main reason of the existence of this builder, or if it has more advantages to the one available as a template on Vercel.

I followed the readme and didn't worked, I get this in the logs:

[GET] /favicon.ico
01:43:36:42
2020-06-18T06:43:36.584Z    undefined   ERROR   Server is not listening Error: Cannot find module '/var/task/__sapper__/build/server/server.js'
Require stack:
- /var/task/launcher.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/var/task/launcher.js:20:14)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
RequestId: 1fd8980d-7146-4da9-aa97-99e5c8c33d8e Error: Runtime exited with error: exit status 1
Runtime.ExitError

Package.json

"scripts": {
    "start": "sapper dev",
    "dev": "sapper dev --port $PORT",
    "build": "sapper build",
    "cy:run": "cypress run",
    "cy:open": "cypress open",
    "test": "run-p --race dev cy:run"
  },

Server.js

import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import * as sapper from '@sapper/server';

const { PORT = 3000, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';

const app = polka() // You can also use Express
app.use(
  compression({ threshold: 0 }),
  sirv('static', { dev }),
  sapper.middleware()
)

// if (!process.env.VERCEL_REGION) {
  app.listen(PORT, err => {
    if (err) console.log('error', err);
  });
// }

export default app
roelandxyz commented 4 years ago

I just tried it and it works fine. Did you ignore the __sapper__ folder?

thgh commented 4 years ago

@cybertouchllc Please try out the new installation option or check out the examples folder.