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

Bundle Error #25

Open
CanKattwinkel opened this issue Aug 8, 2018 · 9 comments
Open

Bundle Error #25

CanKattwinkel opened this issue Aug 8, 2018 · 9 comments
Labels

Comments

@CanKattwinkel
Copy link

Hello,

I tried to use your lib in an Angular project. Sadly it doesn't work due to some build error.


ERROR in ./node_modules/rx-queue/bundles/rx-queue.umd.js
Module not found: Error: Can't resolve '../../package.json' in '~/queue-error/node_modules/rx-queue/bundles'

Steps to reproduce:

  1. Create a new Angular project with @angular/cli ng new queue-error
  2. cd queue-error
  3. Install Rx-Queue: yarn add rx-queue
  4. Copy code to the app.component.ts:
import { Component } from '@angular/core';

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

  ngOnInit() {
    const queue = new RxQueue()
    queue.next(1)
    queue.next(2)
    queue.next(3)

    queue.subscribe(console.log);
  }

}
  1. start appliaction: yarn start

Or use my reproduction repo:
https://github.com/CanKattwinkel/rx-queue-issue

  1. yarn install
  2. yarn start
  3. Now you get the error.
@huan huan added the bug label Aug 8, 2018
@huan
Copy link
Owner

huan commented Aug 8, 2018

It's great to see my rx-queue has been used in your Angular project!

This issue was caused by we try to get the npm version from the package.json, but we have only used it in the node.js environment before, and in the Angular bundle environment, there's no package.json at all, because the code was bundled.

I had just added a commit to fix this, please try the latest version v 0.4.28, and let me know if this issue was fixed.

Thanks for reporting this, have a good day!

huan added a commit that referenced this issue Aug 8, 2018
@asimonf
Copy link

asimonf commented Sep 13, 2018

It still happens in 0.4.28.

@huan
Copy link
Owner

huan commented Sep 13, 2018

How did this happen?

We had already catch all exceptions:

https://github.com/zixia/rx-queue/blob/8179faa5443c57b331f72e4a04a6fc5af6524cc3/src/config.ts#L1-L11

@footballencarta
Copy link

I'm having the same problem with Angular 6 as well.

As far as I can tell, the VERSION (and corresponding version() function) aren't actually used for anything. Once I removed the VERSION grabbing stuff locally the package still worked without issue.

@huan
Copy link
Owner

huan commented Sep 16, 2018

Will try this module: https://github.com/rollup/rollup-plugin-json

@CanKattwinkel
Copy link
Author

@zixia

Why does the version needs to be part of the bundle? If anyone is interested in the version he/she would require the package.json file from the node_modules folder.

@huan
Copy link
Owner

huan commented Sep 16, 2018

@CanKattwinkel The version needs to be part of the bundle because I want to get the version from the instance.

This issue should have been fixed from rx-queue@0.6 or above, please feel free to let me know if there still have any problems.

@footballencarta
Copy link

@zixia I agree with @CanKattwinkel - there's no actual need for returning the actual version number from the package. This is the first and only package I've ever come across that does it, and it's the only one that has this particular problem - so the two are definitely related.

What does it do?
It returns the version of the package

Why?
Because we want to run it in smoke tests to check the package has loaded correctly.

What problem is it causing?
In Angular 6+ (which quite a lot of people will be using this with) it errors that the package.json cannot be found, leading to runtime errors (not compile time).

How can this be fixed?
The easiest way to fix this is to return a static value from the existing function as not to break backwards compatibility.

This was the thinking behind the pull request that's now been closed (because you've done all the work yourself anyway, rendering it moot) - and I believe your approach to this problem is incorrect.

@huan
Copy link
Owner

huan commented Sep 17, 2018

@footballencarta thank you for your pull request and sharing your thinking behind the PR.

As I said in reply to your PR, we need to keep it working by fix the problem under angular 6 instead of hard coded the version number inside the source code.

From rx-queue@0.6, the rollup will get the version number from the package.json to the bundle automatically, just like what your PR does.

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

No branches or pull requests

4 participants