-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Failed to import module from component node_modules #4134
Comments
There is a simpler way, that works.
import { Component } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent {
init() {
const chunk = require('lodash.chunk');
console.log(chunk);
}
}; This is not an issue, it can be closed. |
@catull, but that is adding the dependency at the app level. I want the component to have its own package.json and dependencies. Like I said, in the build process I need to separate each component so we can publish them independently to our own private npm repository. |
We don't really support multiple projects/apps at the moment. I understand that your usecase could be fixed by adding a local set of node_modules, but that would also remove the fix for npm linked node modules (#2291). If there's a way to have both working, let me know. |
@filipesilva, linked packages seem to work. Just did the following to reproduce: Using [email protected], create new app, a component, and install sub-dependency: cd $HOME
ng new my-app
cd my-app
ng generate component my-component
cd src/app/my-component
npm init
npm install --save lodash.chunk Create test package and link it to app: cd $HOME
mkdir test-package
cd test-package
echo 'module.exports = "test-package";' > index.js
npm init
npm link
cd $HOME/my-app
npm link test-package Require both packages in my-component: // src/app/my-component/my-component.component.ts
import { Component, OnInit } from '@angular/core';
+ let test = require('test-package');
+ let chunk = require('lodash.chunk');
+ console.log(test);
+ console.log(chunk); Add component to app template: <!-- src/app/app.component.html -->
+ <app-my-component></app-my-component> Edit webpack's config: // node_modules/angular-cli/models/webpack-build-common.js @ 27
+ // var nodeModules = path.resolve(projectRoot, 'node_modules');
+ var nodeModules = 'node_modules'; // this works Now both Am I missing something or do linked packages work just fine without #2291? Maybe webpack fixed it since September? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
macOS El Capitan
angular-cli: 1.0.0-beta.24
node: 6.9.1
os: darwin x64
@angular/common: 2.4.2
@angular/compiler: 2.4.2
@angular/core: 2.4.2
@angular/forms: 2.4.2
@angular/http: 2.4.2
@angular/platform-browser: 2.4.2
@angular/platform-browser-dynamic: 2.4.2
@angular/router: 3.4.2
@angular/compiler-cli: 2.4.1
Repro steps.
Create a component, add a package.json to the component, and install a dependency.
Then require the dependency:
The log given by the failure.
Mention any other details that might be useful.
I can fix the module resolve in the webpack config, by changing line 39 of webpack-build-common.ts to just use
node_modules
and let it resolve:The reason I need nested node_modules is because we are developing components in a single repo, but we want to separate them out in our deployment build so each component can have its own dependencies.
Is there something I'm missing to make this work out of the box?
The text was updated successfully, but these errors were encountered: