Closed aifer2007 closed 6 years ago
For example, import a node core module 'os' and a normal module 'q' at the same time in app.component.ts:
import { Component } from '@angular/core';
// to import node core modules
import { CpuInfo } from 'os'
// to import common node modules
import { when } from 'q';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
constructor(cpu:CpuInfo){
when(); // from 'q' module
}
}
Then
ng serve --open
...
ERROR in src/app/app.component.ts(4,25): error TS2307: Cannot find module 'os'.
webpack: Failed to compile.
ONLY 'os' reports error: Cannot find module 'os'. 'q' module works well.
Angular applications are web applications and run in a browser environment not a nodejs environment. As a result, nodejs builtins do not exist in that context.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
I'm submitting a...
Current behavior
I use node core modules (os, fs, path, child_process, dgram, etc.) in my Angular4 project. I create a new angular4 project:
Then I try to import 'os' module in app.component.ts file
and then
Some errors are reported:
All the node core modules, such as fs, os, child_process, dgram etc., will give the same error
Yet, much extenral node modules work well at the same time.
Expected behavior
How to use node core modules( fs, os, child_process, etc.) in Angular projects?
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment