0

I am trying to create a new project via vue-cli with the webpack-simple template. Everything works until I try to use mongodb.

As soon as I add the line

import mongodb from 'mongodb'

I get the following error.

./node_modules/mongodb/lib/gridfs/grid_store.js Module not found: Error: Can't resolve 'fs' in 'D:\Development\vue-cli-test\node_modules\mongodb\lib\gridfs'

I got rid of this error when I added

node: { fs: 'empty' } 

to my webpack.config.js file.

Now I get the following error

./node_modules/require_optional/node_modules/resolve-from/index.js Module not found: Error: Can't resolve 'module' in 'D:\Development\vue-cli-test\node_modules\require_optional\node_modules\resolve-from'

I use node version 8.9.0

Thanks a lot

3
  • 4
    Seems like webapps are the new smartphones, so I guess we repeat the same answers all over again. Your database connection software does not belong in your web application client. This software is "back end only" so you need to get it out of your build and stop attempting to use it there. Commented Nov 4, 2017 at 11:31
  • 4
    fs package used by mongodb is a file system library for Node environment. You can't run it in browser. Commented Nov 4, 2017 at 11:43
  • 1
    Wow, that's quite embarassing. I don't know how I could confuse this. You guys are absolutely correct. Thanks for waking me up.. Commented Nov 4, 2017 at 12:22

1 Answer 1

1

fs/MongoDB cannot be used in front-end code. Send the data to the sever, then have the server save it to the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.