vercel: [now-next] Module not found: Can't resolve 'request' when importing firebase database

I encountered a error below when deploying to now.

ModuleNotFoundError: Module not found: Error: Can’t resolve ‘request’ in ‘/tmp/5db89640/node_modules/@firebase/database/dist’

My dependencies is only

{
  "dependencies": {
    "antd": "^3.12.3",
    "firebase": "^5.7.3",
    "next": "^7.0.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  }
}

and my now.json is


{
  "version": 2,
  "builds": [
      { "src": "next.config.js", "use": "@now/next" }
  ]
}

The error occured after install firebase.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Fixed in https://github.com/zeit/now/pull/2924, currently on canary builder.

@diogoviannaaraujo I had the same issue for a week and just fixed it. Try:

  • Installing next@9.0.4-canary.7+
  • Installing Node v10.16.2+ (can use nvm)
  • Deleting your node_modules folder and installing again (yarn or npm i)
  • In your now.json file, put:
//...
"version": 2,
"name": "project-name",
"builds": [
    {
      "src": "package.json",
      "use": "@now/next@canary",
      "config": { "maxLambdaSize": "10mb" }
    }
  ],
//...

Not sure exactly which step fixed it for me, but after doing all of them, my app now deploys via now and now dev for Next 9.

I am using firebase in nextapp and unable while deploying to ZEIT it shows error

 ./node_modules/@firebase/database/dist/index.node.cjs.js
                          Module not found: Can't resolve 'request' in '/tmp/6d82ffed/node_modules/@firebase/database/dist'
2019-07-08T17:56:01.203Z  > Build error occurred
2019-07-08T17:56:01.203Z  Error: > Build failed because of webpack errors
                              at Object.build [as default] (/tmp/6d82ffed/node_modules/next/dist/build/index.js:192:15)
                              at <anonymous>
                              at process._tickCallback (internal/process/next_tick.js:188:7)

Error log comes out to be this,

My package.json file looks like this

{
  "name": "suvidha-next",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "now-start": "node server.js",
    "dev": "node server.js",
    "build": "next build",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@material-ui/core": "^4.1.3",
    "@zeit/next-css": "^1.0.1",
    "cross-env": "^5.2.0",
    "express": "^4.17.1",
    "firebase": "^6.2.4",
    "next": "^8.1.0",
    "react": "^16.8.6",
    "react-autosuggest": "^9.4.3",
    "react-dom": "^16.8.6",
    "react-google-invisible-recaptcha": "^0.2.11",
    "react-icons": "^3.7.0",
    "react-modal": "^3.8.2",
    "react-multi-carousel": "^1.4.6",
    "react-redux": "^5.0.1",
    "react-scroll-locky": "^1.5.0",
    "react-scroll-up-button": "^1.6.4",
    "react-select": "^3.0.4",
    "react-tooltip": "^3.10.0",
    "redux": "^3.6.0",
    "redux-devtools-extension": "^2.13.2",
    "redux-persist": "^5.10.0",
    "url-loader": "^2.0.1"
  }
}

and next-config.js looks like this

const withCSS = require('@zeit/next-css')

module.exports = withCSS({
  target: 'serverless',
  webpack: function (config) {
    config.module.rules.push({
      test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
      use: {
        loader: 'url-loader',
        options: {
          limit: 100000,
          name: '[name].[ext]'
        },
        
      },
      
     
    },
    )
    return config
  }
},

)

Hope it helps for solving the error.

Use this library GitHub repo https://github.com/dksami/NextBigThing and use whatever library you need and it will work however I am afraid that database firebase might not work / if fix? star the repo Feel Free to Fork @mtrabelsi @samantonis @skoch

same thing for me when using IOTA library, time to find a serious deployment tools, we pay premium for shitty-crappy-weirdo tools

I also tried deploying static version but didn’t get that working either (the website builds and loads fine , but firebase stuff fails )

I’m seeing this issue as well when trying to use firebase with a serverless target in next.config.js.

Thanks for putting that repo together @CarlosBolanos

This may be a duplicate issue.

I’m having the same issue as youkyll.

i created a small github repo (https://github.com/CarlosBolanos/next-redux-firebase)

i was able to deploy to now the part with next and the redux wrapper, but when i require firebase the now cli fail to deploy with the error ‘Can’t resolve ‘request’ in ‘/tmp/73d905f1/node_modules/@firebase/database/dist’’.

hope this helps…