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

Can't resolve 'crossfilter' in '~node_modules\dc' #6354

Closed
alexkibler opened this issue May 17, 2017 · 15 comments
Closed

Can't resolve 'crossfilter' in '~node_modules\dc' #6354

alexkibler opened this issue May 17, 2017 · 15 comments
Assignees
Labels
needs: investigation Requires some digging to determine if action is needed

Comments

@alexkibler
Copy link

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.3
node: 6.10.3
os: win32 x64
@angular/common: 4.1.2
@angular/compiler: 4.1.2
@angular/core: 4.1.2
@angular/forms: 4.1.2
@angular/http: 4.1.2
@angular/platform-browser: 4.1.2
@angular/platform-browser-dynamic: 4.1.2
@angular/router: 4.1.2
@angular/cli: 1.0.3
@angular/compiler-cli: 4.1.2

Repro steps.

ng new testproj && cd testproj
npm install --save dc

replace app.component.ts with

import { Component } from '@angular/core';
import * as crossfilter from 'crossfilter2';
import * as d3 from 'd3';
import * as dc from 'dc';

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

    constructor() {
        this.setupCharts();
    }
  
    setupCharts() {
        const chart = dc.barChart('#test');
        chart.width(768);
    }
}

The log given by the failure.

ERROR in ./~/dc/dc.js
Module not found: Error: Can't resolve 'crossfilter' in 'C:\Users\akibler\Documents\Visual Studio 2017\Projects\testproj\node_modules\dc'
 @ ./~/dc/dc.js 10707:8-42
 @ ./src/app/app.component.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

Desired functionality.

Let me use DC?

Mention any other details that might be useful.

This issue with dc.js makes it seem like we need to be able to add a "resolve" to the webpack config. I'm not sure that this is possible with .angular-cli.json

@sumitarora sumitarora self-assigned this May 17, 2017
@sumitarora sumitarora added the needs: investigation Requires some digging to determine if action is needed label May 17, 2017
@sumitarora
Copy link
Contributor

@alexkibler Is there a repo replicating the issue?

@alexkibler
Copy link
Author

@sumitarora Sure, I've just created one: https://github.com/alexkibler/DCJSCrossfilterProblem

If you clone and npm install followed by ng build, you'll see it blows up with the error I listed above.

@clydin
Copy link
Member

clydin commented May 17, 2017

Quickly looking over the "dc" package, I wouldn't expect that to work. It has a dependency on the "crossfilter2" package not "crossfilter".

@alexkibler
Copy link
Author

@clydin yeah, I see that as well. It's something to do with crossfilter changing, so the dc team switched their dependency to crossfilter2 but still reference it as crossfilter. But I can't figure out how to do the "reference it as crossfilter" thing mentioned in the Issue I linked above

@clydin
Copy link
Member

clydin commented May 17, 2017

this is really a fatal defect in the library.
As an ugly workaround you can rename the directory in node modules to the expected name.

@alexkibler
Copy link
Author

Right, I knew that, but that means all of our developers have to do that, and any time we want to update the version, or reinstall node_modules for whatever reason, we'll have to remember to do that.

The point of this post was that webpack itself has the workaround to let you alias, and I was hoping the CLI would support this.

@clydin
Copy link
Member

clydin commented May 18, 2017

Without ejecting the config, there is no support for that.

As to the renaming, you could add a post install script to package.json to handle the renaming until the package is fixed.

I'd also recommend raising an issue with the package, if not already present.

@alexkibler
Copy link
Author

alexkibler commented May 18, 2017 via email

@sumitarora
Copy link
Contributor

Closing as above @alexkibler Please reopen the issue if needed.

@alexkibler
Copy link
Author

@clydin Do you have a recommendation for how to do a rename in the postinstall? Sorry, I haven't really done much with npm scripts

@clydin
Copy link
Member

clydin commented May 18, 2017

Untested but something like the following should work on Linux/MacOS (not sure of the equivalent for Windows):

"postinstall": "if [ -e node_modules/crossfilter2 ]; then mv node_modules/crossfilter2 node_modules/crossfilter; fi"

@alexkibler
Copy link
Author

Thanks! I'm on Windows, though. For what it's worth, renaming the crossfilter directory never helped me anyway, and I actually had to rename it in a line of code in dc.js. Once I did that everything started working. One of the people from DC opened an issue in crossfilter2 to try to fix it permanently but for now I have to change that line in dc.

define(["d3", "crossfilter"], _dc);

changes to

define(["d3", "crossfilter2"], _dc);

You wouldn't know a way to replace a line of text in a file, would you? That's where I'm struggling now, but for now I'm just going to have my team change it manually.

@clydin
Copy link
Member

clydin commented May 18, 2017

There's a package called replace which you could add as a dev dependency. It's unmaintained but for a simple temporary workaround it should do what you need.

something like the following should work:

replace "crossfilter" "crossfilter2" path_to_dc.js_file

@alexkibler
Copy link
Author

Yeah, I tried that, but when I gave it "node_modules/dc/dc.js" as the file, it said it couldn't find it

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed
Projects
None yet
Development

No branches or pull requests

3 participants