Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to webpack bundle - Module not found: Error: Can't resolve 'osx-temperature-sensor' and 'child_process' #230

Closed
acds opened this issue May 30, 2019 · 18 comments

Comments

@acds
Copy link

acds commented May 30, 2019

Describe the bug
trying to build Webpack with no intention of using osx-temprarture-sensor, and not invoking that systeminformation function.

If there a way to tell the build process not to include the osx-temprarture-sensor package. I I do try and add that as a package dependency it then required and has smc dependency issues, that ideally, I'd rather not then deal with.

I expect this is somewhat related: #25

To Reproduce
Steps to reproduce the behavior:

  1. used function '...'
  2. code snippet '....'
  3. start app / code
  4. See output/error '....'
Module not found: Error: Can't resolve 'osx-temperature-sensor' in...' 

Current Output
If applicable, add output to help explain your problem.

Expected behavior
A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • systeminformation package version:
  • OS: [e.g. macOS] macOS - but also building on linux etc.
  • Hardware [e.g. MacBook Pro 13]

Additional context
Add any other context about the problem here.

trying to use Webpack.

@sebhildebrandt
Copy link
Owner

sebhildebrandt commented May 30, 2019

@acds: just to be clear: are you trying to build a client/frontend side app (like with a framework like react or angular) or is it server/backend side (node js or eventually electron)?

If you are trying to build the first one: this will not work! Systeminformation is only intended do be used server/backend side.

If you build a server/backend side app, can you point me to some code how you are using webpack here?

@acds
Copy link
Author

acds commented May 30, 2019

Hi @sebhildebrandt - Yes its server side.

I'm using .Net Core Node Services.

I have the js script as an embedded resources taking advantage of EmbededResouceReader and StringAsTempFile to provide named module exports to the NodeServices.InvokeExportAsync.

with the javascript like this:

const osxTemp = require('systeminformation');

module.exports = {
    mdfg_mem: function(callback, seed) {

        console.log("in mem");

        let result = null;
        si.mem()
            .then( data => {
                   console.log(data);
                    callback(null, data);
                }
                else 
                {
                    callback(null, null);
                }
            })
            .catch(error => {
                callback(error, null);
            });
    }
};

However, on deployment (outside of development) I need to copy the package.json and run npm install such that node can find the systeminformation packages & dependencies.

Alternatively I can setup Webpack to generate a bundled js file, and embed and reference that instead...

Here is the package.json

{
  "name": "xxxx",
  "version": "1.0.0",
  "description": "Description",
  "main": "./Scripts/index.js",
  "scripts": {
    "build:debug": "webpack --mode=development --config webpack.config.js --progress --profile",
    "build:production": "webpack --mode=production --config webpack.config.js --progress --profile",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "xxxxxx",
  "license": "ISC",
  "dependencies": {
    "systeminformation": "^4.5.1"
  },
  "devDependencies": {
    "ts-loader": "^6.0.1",
    "typescript": "^3.4.5",
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2"
  }
}

and webpack.config.js:

const path = require('path');
const webpack = require('webpack');

module.exports = (env, args) =>({
    resolve: {
        extensions: ['.ts', '.js']
    },
    devtool: args.mode === 'development' ? 'inline-source-map' : 'none',
    module: {
        rules: [
            {
                test: /\.ts?$/,
                loader: 'ts-loader'
            }
        ]
    },
    entry:  {
        'index'  : './Scripts/myfile.js',
    },
    output: {
        path: path.join(__dirname, '/Scripts'),
        filename: '[name].js'
    }
});

hoverer I get the following errors:

WARNING in ./node_modules/systeminformation/lib/cpu.js
Module not found: Error: Can't resolve 'osx-temperature-sensor' in '<path to projct>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/cpu.js
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfilejs

ERROR in ./node_modules/systeminformation/lib/users.js
Module not found: Error: Can't resolve 'child_process' in ''<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/users.js 16:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/util.js
Module not found: Error: Can't resolve 'child_process' in '/<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/util.js 18:14-38 19:13-37 20:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/battery.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/battery.js 16:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/internet.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/internet.js 16:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/system.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/system.js 16:13-37 17:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/graphics.js
Module not found: Error: Can't resolve 'child_process' in '/<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/graphics.js 16:13-37 17:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/memory.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/memory.js 17:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/osinfo.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/osinfo.js 17:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/filesystem.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/filesystem.js 16:13-37 17:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/processes.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/processes.js 17:13-37 18:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/cpu.js
Module not found: Error: Can't resolve 'child_process' in '/<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/cpu.js 17:13-37
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/network.js
Module not found: Error: Can't resolve 'child_process' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/network.js 17:13-37 18:17-41
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/util.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/util.js 17:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/battery.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/battery.js 17:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/system.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/system.js 18:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/osinfo.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/osinfo.js 19:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/cpu.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/cpu.js 18:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/network.js
Module not found: Error: Can't resolve 'fs' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/network.js 19:11-24
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js

ERROR in ./node_modules/systeminformation/lib/dockerSocket.js
Module not found: Error: Can't resolve 'net' in '<path to project>/node_modules/systeminformation/lib'
 @ ./node_modules/systeminformation/lib/dockerSocket.js 16:12-26
 @ ./node_modules/systeminformation/lib/docker.js
 @ ./node_modules/systeminformation/lib/index.js
 @ ./Scripts/myfile.js
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build:debug: `webpack --mode=development --config webpack.config.js --progress --profile`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build:debug script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     <user folder>/.npm/_logs/2019-05-30T22_26_17_309Z-debug.log

@acds acds changed the title trying to webpack bundle - Module not found: Error: Can't resolve 'osx-temperature-sensor' trying to webpack bundle - Module not found: Error: Can't resolve 'osx-temperature-sensor' and 'child_process' May 30, 2019
@sebhildebrandt
Copy link
Owner

sebhildebrandt commented May 30, 2019

I did not worked with webpack on backend side ... but I found this blog post https://medium.com/code-oil/webpack-javascript-bundling-for-both-front-end-and-back-end-b95f1b429810 and according to this (at the end of the post) you would need to add to your config:

module.exports = {
  node: {
    fs: 'empty'
    child_process: 'empty'
    net: 'empty'
    'osx-temperature-sensor': 'empty'
  },
  ...
}

I guess you need to play around a little with this ... can you provide the correct answer, if you have success with it ...?

@sebhildebrandt
Copy link
Owner

@acds : Did you had time to play around with the web pack options? As this is probably not really an issue of systeminformation, I would like to close the issue. But I would be happy if you post your progress here for reference.

@sebhildebrandt
Copy link
Owner

Closing this, seems not to be an issue of systeminformation, rather than web pack configuration.

@adambailey-
Copy link

Hey @sebhildebrandt! Thanks for finding this. I'm also having this problem, but when I try adding the suggested code to the end of my webpack configuration, I get an error and some warnings.

Screen Shot 2020-03-16 at 9 42 26 AM

Any advice you could provide would be helpful.

@adambailey-
Copy link

Realized I needed to quote it. Regardless, it still does not fix the module not found warning :)

@sebhildebrandt
Copy link
Owner

Just to be sure:

can you provide your package.json?

@sebhildebrandt
Copy link
Owner

@adambailey- not sure if you were notified ...

Can you provide your package.json?

@adambailey-
Copy link

Sure! I've removed some information in there that is definitely not useful (mostly release and testing information).

It's worth noting that this is an Electron app, and that the warning is especially visible when using npm run watch, as it shows up every time Webpack rebuilds

{
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "app": "electron .",
    "build": "webpack --env dev",
    "watch": "webpack --env dev --watch",
  },
  "engines": {
    "node": ">=12.8.1",
    "npm": ">=6.10.2"
  },
  "devDependencies": {
    "@babel/cli": "7.7.5",
    "@babel/core": "7.7.5",
    "@babel/plugin-transform-runtime": "7.7.6",
    "@babel/preset-env": "7.7.6",
    "@babel/preset-react": "7.7.4",
    "@material-ui/core": "4.8.0",
    "@material-ui/icons": "4.5.1",
    "@sentry/webpack-plugin": "1.9.3",
    "@sentry/wizard": "1.0.2",
    "@types/enzyme": "3.10.4",
    "@types/jest": "24.0.23",
    "@types/lodash": "4.14.149",
    "@types/node": "12.12.19",
    "@types/react": "16.9.16",
    "@types/react-dom": "16.9.4",
    "@types/react-redux": "7.1.5",
    "@types/react-router-dom": "5.1.3",
    "@types/request": "2.48.4",
    "@types/semver": "6.2.0",
    "babel-loader": "8.0.6",
    "colors": "1.4.0",
    "css-loader": "3.4.0",
    "electron": "7.1.12",
    "electron-builder": "22.2.0",
    "electron-notarize": "0.2.1",
    "electron-react-devtools": "0.5.3",
    "enzyme": "3.10.0",
    "jest": "24.9.0",
    "lodash": "4.17.15",
    "native-ext-loader": "2.3.0",
    "node-machine-id": "1.1.12",
    "node-rsa": "1.0.7",
    "node-sass": "4.13.1",
    "node-uuid": "1.4.8",
    "nodeunit": "0.11.3",
    "prettier": "1.19.1",
    "prop-types": "15.7.2",
    "react": "16.12.0",
    "react-compound-slider": "2.4.0",
    "react-dom": "16.12.0",
    "react-redux": "7.1.3",
    "react-router-dom": "5.1.2",
    "reduce-reducers": "1.0.4",
    "redux": "4.0.4",
    "redux-devtools-extension": "2.13.8",
    "redux-persist": "6.0.0",
    "redux-persist-electron-storage": "2.1.0",
    "redux-saga": "1.1.3",
    "redux-thunk": "2.3.0",
    "request": "2.88.0",
    "sass-loader": "8.0.0",
    "semver": "6.3.0",
    "source-map-loader": "0.2.4",
    "spectron": "7.0.0",
    "sprintf": "0.1.5",
    "string-to-arraybuffer": "1.0.2",
    "style-loader": "1.0.2",
    "ts-jest": "24.2.0",
    "ts-loader": "6.2.1",
    "tslint": "5.20.1",
    "tslint-config-prettier": "1.18.0",
    "tslint-react": "4.1.0",
    "typescript": "3.7.3",
    "url-loader": "3.0.0",
    "webpack": "4.41.3",
    "webpack-cli": "3.3.10",
    "webpack-merge": "4.2.2"
  },
  "dependencies": {
    "@sentry/electron": "1.1.0",
    "dotenv": "8.2.0",
    "electron-is-dev": "1.1.0",
    "electron-log": "3.0.9",
    "electron-store": "5.1.0",
    "electron-updater": "4.2.2",
    "electron-windows-badge": "1.0.5",
    "keytar": "5.0.0",
    "systeminformation": "4.23.1"
  }
}

@sebhildebrandt
Copy link
Owner

@adambailey- for OS X you also need to add osx-temperature-sensorto your dependencies

npm install osx-temperature-sensor --save

@adambailey-
Copy link

adambailey- commented Mar 16, 2020

Installing that package unfortunately graduated the warning to an error. It's also worth noting that I don't actually need to read the temperature, I just want to suppress the warning / error.

Error appears both with and without the suggested Webpack changes above

Screen Shot 2020-03-16 at 10 11 32 AM

@sebhildebrandt
Copy link
Owner

sebhildebrandt commented Mar 16, 2020

@adambailey- ... which you probably then also need to add to the webpack config ... just a suggestion as I do not work with webpack at backend: so something like this:

module.exports = {
  node: {
    fs: 'empty',
    child_process: 'empty',
    net: 'empty',
    'osx-temperature-sensor': 'empty',
    smc: 'empty'
  },
  ...
}

@adambailey-
Copy link

Same error. By the way, our Webpack setup isn't what that article is describing with a frontend and backend config. We have one config, whose target is node. I'll put the contents below. Also worth noting that adding this to the Webpack config still results in some WebStorm warnings. Changing the target to web doesn't change

Screen Shot 2020-03-16 at 10 29 44 AM

// webpack.config.base.js

const path = require('path');
const webpack = require('webpack');

const entryFiles = {
  'index': './src/js/index.tsx'
};

module.exports = {
  entry: entryFiles,
  resolve: {
    extensions: ['json', '.js', '.jsx', '.ts', '.tsx'],
    alias: {
      node_modules: path.resolve(__dirname, './node_modules/'),
      components: path.resolve(__dirname, './src/js/components/'),
      classes: path.resolve(__dirname, './src/js/classes/'),
      config: path.resolve(__dirname, './src/config/'),
      locale: path.resolve(__dirname, './src/js/locale/'),
      constants: path.resolve(__dirname, './src/js/constants'),
      styles: path.resolve(__dirname, './src/styles/')
    }
  },
  target: 'node',
  externals: [{
    'electron-store': 'electron-store'
  }],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js',
    sourceMapFilename: '[name].js.map',
    libraryTarget : 'commonjs2'
  },
  module: {
    rules: [
      {
        enforce: 'pre',
        test: /\.js$/,
        loader: 'source-map-loader'
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env', '@babel/preset-react']
            }
          }
        ]
      },
      {
        test: /\.scss$/,
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' },
          { loader: 'sass-loader' }
        ]
      },
      {
        test: /\.node$/,
        loader: 'native-ext-loader'
      },
      {
        test: /.*\.svg$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 16384
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new webpack.ExternalsPlugin('commonjs', [
      'electron'
    ])
  ],
  node: {
    fs: 'empty',
    child_process: 'empty',
    net: 'empty',
    'osx-temperature-sensor': 'empty',
    smc: 'empty'
  }
};

@f3l1x
Copy link

f3l1x commented Apr 7, 2020

Hi guys. This helped me.

module.exports = {
  plugins: [
    new webpack.IgnorePlugin(/osx-temperature-sensor/)
  ]
}

No more warning.

@adambailey-
Copy link

Thank you so much!

@drogerie21
Copy link

drogerie21 commented May 19, 2021

Not working for me.
I´am using webpack 5; altough including the snippet above (new webpack.IgnorePlugin(/osx-temperature-sensor/) webpack throws the following error:
WARNING in ./node_modules/systeminformation/lib/cpu.js 1107:20-53 Module not found: Error: Can't resolve 'osx-temperature-sensor' in '[PATH TO NODE_MODULES]/node_modules/systeminformation/lib' @ ./node_modules/systeminformation/lib/index.js 28:12-28 @ ./source/main/index.ts 10:42-70
Can anyone help?

EDIT: [SOLUTION]:
For anyone having the same problem: wepback 5 changed the syntax, this is the solution for webpack 5:
new webpack.IgnorePlugin({ resourceRegExp: /osx-temperature-sensor$/, }),

@n3g2
Copy link

n3g2 commented Dec 1, 2022

// for target web
// for Windows electron main

resolve: {
  fallback: {
    'osx-temperature-sensor': false,
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants