Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Failed to import module from component node_modules #4134

Copy link
Copy link
@elclanrs

Description

@elclanrs
Issue body actions

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.

ng generate component my-component
cd src/app/my-component
echo {} > package.json
npm install --save lodash.chunk

Then require the dependency:

// my-component.component.ts

let chunk = require('lodash.chunk');

The log given by the failure.

ERROR in ./src/app/my-component/my-component.component.ts
Module not found: Error: Can't resolve 'lodash.chunk' in '/Users/myuser/Documents/my-project/src/app/my-component'

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:

// const nodeModules = path.resolve(projectRoot, 'node_modules');
const nodeModules = 'node_modules'; // this works

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?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.