Quasar Framework (VueJS) - "UI" compiled with errors (If import web3)

Viewed 561

I use Quasar CLI version 1.2.1 and library web3 version ^1.5.2

it's an error when i use:

import Web3 from 'web3'

Log Error:

App • Chaining "UI" Webpack config App • WAIT • Compiling of "UI" in progress... App • DONE • "UI" compiled with errors • 6809ms

App • ERROR • UI in ./node_modules/cipher-base/index.js

Module not found: Can't resolve imported dependency "stream" Did you forget to install it? You can run: yarn add stream

App • ERROR • UI in ./node_modules/eth-lib/lib/bytes.js

Module not found: Can't resolve imported dependency "crypto" Did you forget to install it? You can run: yarn add crypto

App • ERROR • UI in ./node_modules/ethereumjs-util/dist.browser/account.js

Module not found: Can't resolve imported dependency "assert" Did you forget to install it? You can run: yarn add assert

App • ERROR • UI in ./node_modules/swarm-js/node_modules/eth-lib/lib/bytes.js

Module not found: Can't resolve imported dependency "crypto" Did you forget to install it? You can run: yarn add crypto

App • ERROR • UI in ./node_modules/web3-eth-accounts/lib/index.js

Module not found: Can't resolve imported dependency "crypto" Did you forget to install it? You can run: yarn add crypto

App • ERROR • UI in ./node_modules/web3-providers-http/lib/index.js

Module not found: Can't resolve imported dependency "http" Did you forget to install it? You can run: yarn add http

App • ERROR • UI in ./node_modules/web3-providers-http/lib/index.js

Module not found: Can't resolve imported dependency "https" Did you forget to install it? You can run: yarn add https

App • ERROR • UI in ./node_modules/xhr2-cookies/dist/xml-http-request.js

Module not found: Can't resolve imported dependency "http" Did you forget to install it? You can run: yarn add http

App • ERROR • UI in ./node_modules/xhr2-cookies/dist/xml-http-request.js

Module not found: Can't resolve imported dependency "https" Did you forget to install it? You can run: yarn add https

App • ERROR • UI in ./node_modules/xhr2-cookies/dist/xml-http-request.js

Module not found: Can't resolve imported dependency "os" Did you forget to install it? You can run: yarn add os

App • COMPILATION FAILED • Please check the log above for details.

2 Answers

You are trying to use a nodejs module in the browser.

If you carefully read the documentation it says:

In the Browser

Use the prebuilt dist/web3.min.js

So what you would need to do is: import Web3 from 'web3/dist/web3.min.js'

Related