Webpack Errors - Cannot Resolve 'crypto', 'http', and 'https' in Vue.js - node.js

Question Background
I'm trying to add Wallet Connect to our project(Vue.js), form here: https://docs.walletconnect.com/quick-start/dapps/web3-provider, I used this command to install it.
import it in my js file
import Web3 from 'web3'
import WalletConnectProvider from '#walletconnect/web3-provider'
it shows those errors:
ERROR Failed to compile with 7 errors
These dependencies were not found:
* crypto in ./node_modules/eth-lib/lib/bytes.js, ./node_modules/web3-eth-accounts/lib/index.js and 1 other
* http in ./node_modules/xhr2-cookies/dist/xml-http-request.js
* https in ./node_modules/xhr2-cookies/dist/xml-http-request.js
To install them, you can run: npm install --save crypto http https
Try
I install those packages.
npm i crypto-browserify
npm i https-browserify
npm i stream-http
Then edit my vue.config.js files:
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
},
},
and the errors becomes:
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
configuration.resolve has an unknown property 'fallback'.
These properties are valid:
object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, concord?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
This is my package.json file look like:
{
"dependencies": {
"#walletconnect/web3-provider": "^1.7.8",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"os": "^0.1.2",
"stream": "^0.0.2",
"stream-http": "^3.2.0",
"vue": "^2.6.10",
"web3": "^1.7.3",
},
"devDependencies": {
"#vue/cli-service": "^3.7.0",
"webpack": "^4.39.3",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2",
"webpack-plugin-hash-output": "^3.2.1",
"webpack-spritesmith": "^1.0.1",
}
}
and my node version is v10.24.1, the version still can't be upgraded temporarily.
v10.24.1
As seen from the above, I have installed the suggested packages from the errors (crypto-browserify, stream-http, and https-browserify) and have included them in the vue.config.js.
How can I solve this?

You are using Webpack 4. The fallback option is only available from Webpack >=5.0.0 onwards.
For Webpack 4, consider using alias option.

Related

React/Rails app: webpack Webpacker::Manifest::MissingEntryError

I have looked through and tried all of the existing solutions on Stack Overflow. I have:
changed my node version
installed rails:webpacker over and over
deleted node_modules and public/packs folder
ran yarn install, bundle
but I keep getting this error:
Webpacker::Manifest::MissingEntryError
Webpacker can't find hello_react in .../public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
The line giving an error:
<%= javascript_pack_tag 'hello_react' %>
My versions:
node: v16.14.2
Rails 6.0.6
my package.json:
{
"name": "appname",
"private": true,
"dependencies": {
"#babel/preset-react": "^7.18.6",
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"turbolinks": "^5.2.0",
"webpack": "4.46.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}
}
I cannot move past this error, what am I missing?

Webpack resolve.fallback not working. Module not found: Error: Can't resolve 'crypto' in node_modules\aws4

I have a nodejs app created through the Vue CLI. I need to use the aws4 node module to sign my requests. However, when I use the aws4 module the app fails to serve due to the following error:
ERROR in ./node_modules/aws4/aws4.js 4:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\henry\Repos\AWS4 TEST\aws4-test\node_modules\aws4'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
I got this error for the 3 imports in the aws module: crypto, url and querystring.
I read the error message and saw that the version of webpack the vue cli uses is 5+ so the core modules such as crypto are not included anymore.
(I've never really used webpack before, but the instructions seems simple.)
I created a new file in my project webpack.config.js and added the following:
module.exports = {
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
},
},
};
I then installed the crypto-browserify package.
I still get the error, it's make 0 difference.
I've looked online and have tried solutions suggested for the crypto not found issue. None of them seem to work either. I've tried:
Adding this to the package.json
"browser": {
"crypto": false
}
Adding the crypto object to the paths object in tsconfig.json
"compilerOptions": {
"baseUrl": "./",
"paths": {
"crypto": ["node_modules/crypto-browerify"],
}
I tried using the node module: node-polyfill-webpack-plugin. Which did resolve the issue for url and querystring (as soon as the module was imported). But the issue with crypto remains.
Here is my package.json
{
"name": "aws4-test",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"dependencies": {
"aws4": "^1.11.0",
"axios": "^0.27.2",
"core-js": "^3.8.3",
"crypto-browserify": "^3.12.0",
"crypto-js": "^4.1.1",
"node-polyfill-webpack-plugin": "^2.0.0",
"vue": "^2.6.14",
"vue-class-component": "^7.2.3",
"vue-property-decorator": "^9.1.2",
"vue-router": "^3.5.1",
"vuex": "^3.6.2"
},
"devDependencies": {
"#types/aws4": "^1.11.2",
"#types/jest": "^27.0.1",
"#typescript-eslint/eslint-plugin": "^5.4.0",
"#typescript-eslint/parser": "^5.4.0",
"#vue/cli-plugin-babel": "~5.0.0",
"#vue/cli-plugin-eslint": "~5.0.0",
"#vue/cli-plugin-router": "~5.0.0",
"#vue/cli-plugin-typescript": "~5.0.0",
"#vue/cli-plugin-unit-jest": "~5.0.0",
"#vue/cli-plugin-vuex": "~5.0.0",
"#vue/cli-service": "~5.0.0",
"#vue/eslint-config-airbnb": "^6.0.0",
"#vue/eslint-config-typescript": "^9.1.0",
"#vue/test-utils": "^1.1.3",
"#vue/vue2-jest": "^27.0.0-alpha.2",
"babel-jest": "^27.0.6",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-vue": "^8.0.3",
"eslint-plugin-vuejs-accessibility": "^1.1.0",
"jest": "^27.0.5",
"ts-jest": "^27.0.4",
"typescript": "~4.5.5",
"vue-template-compiler": "^2.6.14"
},
"browser": {
"crypto": false
}
}
To isolate the issue I created a new vue 2 app though the cli then just added the aws4 and axios modules. The fact that the node-polyfill-webpack-plugin works to resolve the errors for all but crypto error seems odd. Perhaps something else is overwritting that.
Thanks for your help.
The reason the webpack config wasn't working was because I am using the vue-cli-service. So to configure the webpack config I needed to edit the vue.config.js file and use the configureWebpack object. Docs here: https://cli.vuejs.org/guide/webpack.html

error on 'fullySpecified' of webpack.config.js - but no config exists

I get this strange error:
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module.rules[1].resolve has an unknown property 'fullySpecified'. These properties are valid:
object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, concord?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, ignoreRootsErrors?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, preferAbsolute?, resolver?, roots?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
when using sls deploy
(to deploy to aws serverless)
however I don't have a webpack.config.js file nor have I ever set a config setting with "fullySpecified" before.
What I have tried:
searching the project for the term: 'fullySpecified' - it does not exist.
no webpack.config.js (as was originally the code)
a webpack.config.js with a basic config:
module.exports = {
target: 'node',
mode: 'production'
};
What I have found:
https://githubmemory.com/repo/AnomalyInnovations/serverless-bundle/issues/259
Context:
The code is 9 months old and worked last time I was working on it
I used npm update
Operating System: linux
Node Version: 14.16.1
Framework Version: 2.61.0 (local)
Plugin Version: 5.4.5
SDK Version: 4.3.0
Components Version: 3.17.1
package.json:
"dependencies": {
"axios": "0.21.1",
"cors": "2.8.4",
"custom-env": "^2.0.1",
"dotenv": "^8.2.0",
"express": "4.16.4",
"stripe": "6.12.1",
"uuid": "3.3.2",
"aws-sdk": "^2.639.0"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0",
"nodemon": "1.18.4",
"serverless-bundle": "^5.0.2",
"serverless-pseudo-parameters": "^2.5.0",
"serverless-webpack": "^5.5.4",
"webpack": "^5.58.0"
}

Module not found: Error: Can't resolve 'fs' in, Node js

When I run my Node.js application I always get Error: Can't resolve 'fs'.
I looked into some questions and tried to change the dependencies in my package.json file.
"dependencies": {
"#types/vexflow": "^3.0.0",
"fs": "^0.0.1-security",
"jszip": "3.7.1",
"loglevel": "^1.6.8",
"socket.io": "^4.2.0",
"typescript-collections": "^1.3.3",
"vexflow": "1.2.93"
},
Is there something else I need to do?
Thanks

Install of jspm to ^0.16.34 has no registry property provided

I am fairly new to front end development and am working through Brian Noyes Aurelia Fundamentals course
I have installed the following;
node-v4.4.4x64
Git-2.8.2-64
Also I ran
npm install jspm --save-dev
and had this result
When I ran
npm install =g jspm gulp http-server
I got messages saying that the following are deprecated.
graceful-fs#3.0.8 and lodash#1.0.2
then when I ran
jsm init
I got an error
The package.json file is
{
"jspm": {},
"devDependencies": {
"jspm": "^0.16.34"
}
}
How do I fix this error?
Credit to user danzinator on github.
The fix:
Adding in the "registry": "npm" line to Package.json (even though the documentation says by default this registry should be used?)
{
"jspm": {
"registry": "npm",
"directories": {
"baseURL": "wwwroot",
"packages": "jspm_packages"
},
"devDependencies": {
"babel": "babel-core#^5.8.22",
"babel-runtime": "^5.8.20",
"browser-sync": "^2.9.3",
"core-js": "^1.1.0",
"gulp": "^3.9.0",
"gulp-tslint": "^3.2.0",
"jspm": "^0.16.2"
}
},
"devDependencies": {
"jspm": "^0.16.2",
"gulp": "^3.9.0",
"gulp-tslint": "^3.2.0",
"browser-sync": "^2.9.3"
}
}

Resources