PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.32k stars 186 forks source link

Module not found: Error: Can't resolve 'crypto' #429

Closed kuworking closed 1 year ago

kuworking commented 1 year ago

Trying to run node-twitter-api-v2 in a nodejs electronjs app, I get this message

Module not found: Error: Can't resolve 'crypto' Module not found: Error: Can't resolve 'https' Module not found: Error: Can't resolve 'zlib' Module not found: Error: Can't resolve 'fs'

I've tried to put in package.json the following without success

  "browser": {
    "crypto": false,
    "stream": false
  },

Then I have added this in webpack.main.config.js

module.exports = {
  /**
   * This is the main entry point for your application, it's the first file
   * that runs in the main process.
   */
  entry: {
    main: './src/main.js',
  },
  // Put your normal webpack config below here
  module: {
    rules: require('./webpack.rules'),
  },
  resolve: {
    fallback: {
      crypto: require.resolve('crypto-browserify'),
      stream: require.resolve('stream-browserify'),
      https: require.resolve('https-browserify'),
      zlib: require.resolve('browserify-zlib'),
      fs: require.resolve('fs-extra'),
    },
  },
}

and yarn-installed the 5 modules.

No success, the error messages are the same.

I paste here the dependencies

"dependencies": {
    "@fontsource/roboto": "4.2.1",
    "@fontsource/staatliches": "4.2.1",
    "browserify-zlib": "0.2.0",
    "cors": "2.8.5",
    "crypto-browserify": "3.12.0",
    "electron-squirrel-startup": "1.0.0",
    "express": "4.17.1",
    "form-data": "4.0.0",
    "fs-extra": "8.0.0",
    "googleapis": "109.0.0",
    "highcharts": "9.3.2",
    "highcharts-react-official": "3.1.0",
    "https-browserify": "1.0.0",
    "isomorphic-unfetch": "3.1.0",
    "papaparse": "5.3.1",
    "path": "0.12.7",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "stream-browserify": "3.0.0",
    "styled-components": "5.3.0",
    "twitter-api-v2": "1.13.0",
    "yahoo-finance": "0.3.7",
    "yahoo-finance2": "2.1.2"
  },
  "devDependencies": {
    "@babel/core": "7.14.6",
    "@babel/preset-react": "7.14.5",
    "@electron-forge/cli": "6.0.0-beta.57",
    "@electron-forge/maker-deb": "6.0.0-beta.57",
    "@electron-forge/maker-rpm": "6.0.0-beta.57",
    "@electron-forge/maker-squirrel": "6.0.0-beta.57",
    "@electron-forge/maker-zip": "6.0.0-beta.57",
    "@electron-forge/plugin-webpack": "6.0.0-beta.57",
    "@marshallofsound/webpack-asset-relocator-loader": "0.5.0",
    "babel-loader": "8.2.2",
    "babel-plugin-styled-components": "1.13.1",
    "copy-webpack-plugin": "9.0.1",
    "css-loader": "5.0.0",
    "electron": "13.1.5",
    "node-loader": "2.0.0",
    "prettier": "2.3.2",
    "style-loader": "2.0.0"
  }

node version 16.13.1, windows 10

kuworking commented 1 year ago

Likely solved by putting the resolve in webpack.renderer.config.js