Deploying on Now razzle with loadable-components

560 Views Asked by At

I am trying to deploy on Now the loadable-components example with Razzle.

I added the following now.json at the root of my project:

{
  "version": 2,
  "builds": [
    {
      "src": "build/server.js",
      "use": "@now/node"
    },
    {
      "src": "build/public/**/*",
      "use": "@now/static"
    }
  ],
  "routes": [
    {
      "src": "/static/(.*)",
      "dest": "build/public/static/$1"
    },
    {
      "src": "/favicon.ico",
      "dest": "favicon.ico"
    },
    {
      "src": "/robots.txt",
      "dest": "robots.txt"
    },
    {
      "src": "/(.*)",
      "dest": "build/server.js"
    }
  ],
  "env": {
    "NODE_ENV": "production"
  }
}

In Now, the build is done without error but in runtime, I have the following error :

2019-10-17T11:39:18.319Z a082c52f-af85-4646-80ca-b946928f8b05 Error: Cannot find module '/var/task/build/loadable-stats.json' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at smartRequire (/var/task/node_modules/@loadable/server/lib/util.js:24:32) at new ChunkExtractor (/var/task/node_modules/@loadable/server/lib/ChunkExtractor.js:173:50) at /var/task/build/server.js:1:7600 at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5) at next (/var/task/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/var/task/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)

Someone already faced this error? If so, how can I solve this? Any input?

Thanks,

1

There are 1 best solutions below

0
On

i think you shouldn't add now.js manually. it's created by webpack when the configuration file is rendered. whether it's craco.config.js or webpack.config.js or razzle.config.js . and that's only beacause you are setting a path and name for the loadable file and initiate it. in that file there are names and paths of the chunks of your project .in my case i was creating a loadable-stats.json in a path and wanting to read the file from another path .