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

Angular 10 CommonJS Warning and Module Not Found Errors #35

Closed
BillyCottrell opened this issue Nov 5, 2020 · 5 comments
Closed

Angular 10 CommonJS Warning and Module Not Found Errors #35

BillyCottrell opened this issue Nov 5, 2020 · 5 comments

Comments

@BillyCottrell
Copy link

BillyCottrell commented Nov 5, 2020

So I have setup a new test project to see how this works. Now the clean build well worked as expected, but when adding this module and add the code in I received following messages:

WARNING in D:\IKANDA\test\ipaddresstest\src\app\app.component.ts depends on 'internal-ip'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

ERROR in ./node_modules/cross-spawn/index.js
Module not found: Error: Can't resolve 'child_process' in 'D:\IKANDA\test\ipaddresstest\node_modules\cross-spawn'

ERROR in ./node_modules/execa/index.js
Module not found: Error: Can't resolve 'child_process' in 'D:\IKANDA\test\ipaddresstest\node_modules\execa'

ERROR in ./node_modules/cross-spawn/lib/util/readShebang.js
Module not found: Error: Can't resolve 'fs' in 'D:\IKANDA\test\ipaddresstest\node_modules\cross-spawn\lib\util'

ERROR in ./node_modules/isexe/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\IKANDA\test\ipaddresstest\node_modules\isexe'

ERROR in ./node_modules/isexe/windows.js
Module not found: Error: Can't resolve 'fs' in 'D:\IKANDA\test\ipaddresstest\node_modules\isexe'

ERROR in ./node_modules/isexe/mode.js
Module not found: Error: Can't resolve 'fs' in 'D:\IKANDA\test\ipaddresstest\node_modules\isexe'

ERROR in ./node_modules/default-gateway/android.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/win32.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/sunos.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/linux.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/openbsd.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/freebsd.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/darwin.js
Module not found: Error: Can't resolve 'net' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/index.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/win32.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/linux.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/default-gateway/darwin.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\default-gateway'

ERROR in ./node_modules/execa/lib/kill.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\execa\lib'

ERROR in ./node_modules/human-signals/build/src/main.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\human-signals\build\src'

ERROR in ./node_modules/human-signals/build/src/signals.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\human-signals\build\src'

ERROR in ./node_modules/internal-ip/index.js
Module not found: Error: Can't resolve 'os' in 'D:\IKANDA\test\ipaddresstest\node_modules\internal-ip'

ERROR in ./node_modules/cross-spawn/lib/parse.js
Module not found: Error: Can't resolve 'path' in 'D:\IKANDA\test\ipaddresstest\node_modules\cross-spawn\lib'

ERROR in ./node_modules/cross-spawn/lib/util/resolveCommand.js
Module not found: Error: Can't resolve 'path' in 'D:\IKANDA\test\ipaddresstest\node_modules\cross-spawn\lib\util'

ERROR in ./node_modules/cross-spawn/node_modules/which/which.js
Module not found: Error: Can't resolve 'path' in 'D:\IKANDA\test\ipaddresstest\node_modules\cross-spawn\node_modules\which'

ERROR in ./node_modules/execa/index.js
Module not found: Error: Can't resolve 'path' in 'D:\IKANDA\test\ipaddresstest\node_modules\execa'

ERROR in ./node_modules/npm-run-path/index.js
Module not found: Error: Can't resolve 'path' in 'D:\IKANDA\test\ipaddresstest\node_modules\npm-run-path'

ERROR in ./node_modules/execa/node_modules/get-stream/buffer-stream.js
Module not found: Error: Can't resolve 'stream' in 'D:\IKANDA\test\ipaddresstest\node_modules\execa\node_modules\get-stream'

ERROR in ./node_modules/merge-stream/index.js
Module not found: Error: Can't resolve 'stream' in 'D:\IKANDA\test\ipaddresstest\node_modules\merge-stream'

This is how my component looks like:

import { Component } from '@angular/core';
import * as internalIp from "internal-ip";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'ipaddresstest';

  ngOnInit(){
    (async () => {
      console.log(await internalIp.v6());
      //=> 'fe80::1'
    
      console.log(await internalIp.v4());
      //=> '10.0.0.79'
    })();
    
    console.log(internalIp.v6.sync())
    //=> 'fe80::1'
    
    console.log(internalIp.v4.sync())
    //=> '10.0.0.79'
  }
}

Even if I were to move this it still gives those errors, any ideas on how to solve them??

Thanks in Advance!

@sindresorhus
Copy link
Owner

This is probably related to Webpack 5. See: https://blog.sindresorhus.com/webpack-5-headache-b6ac24973bf1

I would recommend asking on https://github.com/webpack/webpack/issues or https://github.com/angular/angular/issues instead.

@BillyCottrell
Copy link
Author

BillyCottrell commented Nov 5, 2020

@sindresorhus that's weird since I am using Angular 10.2.0, Webpack 4.44.1 If I am right. I was looking at the package.json of webpack module itself in node_modules/webpack which was 4.44.1. So unless I was looking at the wrong part I don't know why this would be an issue then??

I even went ahead and test it with Angular 9 and this is still the case any ideas?

@sindresorhus
Copy link
Owner

Regardless, this is not the place to ask build-specific questions. This is a problem with the Angular builder or the config you use with it.

@BillyCottrell
Copy link
Author

Hi, I have found out why this is not working in Angular, this is because it is using require which is not supported in browsers. Is it possible to change the documentation and mention that the provided code cannot be used client side since it doesn't support require and can only be used server side. That way you won't have other users asking why they can't use it client side.

It should be possible though to use Requirejs to replace the server side Require, but I don't know how to do this and I can't figure it out for an Angular project.

Anyways I was hoping to use this in my Angular project for a device management system but since this was the only module left to explore for an easy to use setup. Guess I'll have to do some back and forth configuring then, so I can make it work.

Thanks for the help!

@silverwind
Copy link
Collaborator

This module only works in Node, there's no sense in trying to make it work in browsers. See #32 for possible browser support.

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

No branches or pull requests

3 participants