huan / rx-queue

Easy to Use RxJS Queue for Throttle/Debounce/Delay/DelayExecute
https://paka.dev/npm/rx-queue
Apache License 2.0
74 stars 7 forks source link

Bundle Error #25

Open CanKattwinkel opened 6 years ago

CanKattwinkel commented 6 years ago

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);

}

}


5. start appliaction: `yarn start` 

______________________________________________________________

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

1. `yarn install`
1. `yarn start`
1. Now you get the error.
huan commented 6 years ago

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!

asimonf commented 6 years ago

It still happens in 0.4.28.

huan commented 6 years ago

How did this happen?

We had already catch all exceptions:

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

footballencarta commented 6 years ago

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 commented 6 years ago

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

CanKattwinkel commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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.