-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
setTimeout or setInterval type issue when using --watch #348
Comments
Should you not be using |
WebPack is awesome, and I found can be used to generate a single file, even for use outside a browser. For my use case, I am using WebPack to build a single file, which can then be executed by nodejs. In fact, I am prepending "#!/usr/bin/env node" to the top of the file and removing the extension as well so I have a "shell" script. Everything so far has been perfect with WebPack for this use-case. The only issue is this setTimeout issue. What baffles me is that the first build works flawlessly, but on the subsequent builds I get the error. Like I said above, it feels like a different type definition is being used for builds triggered via watch. |
Wow - that's a super unusual use case for WebPack. What's the benefit of using it though? If it's node then commonjs means your require/import statements in TypeScript will just work. Does WebPack actually add anything extra? If I was developing something like that I'd probably be using |
The resulting script will be "installed" like a typical program into /usr/bin. Then it will be able to be executed by various users. In order to accomplish this I examined the following options:
I think it's apparent that there is more going on than just the simple explanation above, but it gives you an idea of why I would decide to do this. At the end of the day, WebPack is allowing me to have a single distributable file with only depends on node, instead of node, npm, and all the dependencies of the project as a whole. I like to think of it akin to static compilation in C#. Create a single executable with no external dependencies. I am aware that many licenses on node modules would frown on this type of distribution. This project, while being open source, would not distribute that "compiled" file. It would only provide directions for building the file and using it for your specific needs. I hope this makes things a little more clear. I have tried other solutions like nexe or enclose, but honestly WebPack was much more configurable and allowed for the whole process to be inlined to a single command to webpack. The webpack --watch made it even better. That is until I used a setInterval. |
Wow. That's pretty cool! |
Okay, so a little more digging and I think I have found the culprit. The typescript package contains the following: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts#L18631-L18632 Now the question is, why does the first run of webpack use the appropriate file, but the subsequent runs do not? |
I don't know but I'm wondering if it's a tsc issue rather than ts-loader? |
Just to test, I put "noLib": true in my tsconfig and I no longer got the issue. But pretty much everything else broke. Obviously not a solution, but confirms my suspicion that the issue is that for some reason when using webpack --watch, runs triggered by file changes are for some reason not properly resolving the correct type definition. Still digging. |
isn't |
Well, I think I have a work-around that I can live with. Instead of using setInterval from the "Global" object, I am explicitly importing it. This works, even for with "--watch"
This doesn't
|
Not sure if I should close this. Probably not an issue for many people. |
Probably not - I'll close this. But I'm glad you've got something that works! |
Just stumbled across this, so this is still an issue, but the workaround works nicely! |
Haha, i just had the same Issue... really weird behaviour though |
Not sure if this is a bug in ts-loader, but I figured I would start here.
Package Versions
@types/node: 6.0.46
ts-loader: 0.9.5
typescript: 2.0.6
webpack: 1.13.3
As you can see, I am using @types/node for NodeJS type definitions.
The issue I am having is with setTimeout and setInterval. In @types/node, the "type" of the number that is returned from setTimeout or setInterval is "NodeJS.Timer". The following is valid and builds perfectly when run with just
webpack
.The problem is when I run
webpack --watch
. On the initial build, everything is fine. Once I change the file which triggers a re-build, I get the following error:It appears to be that on rebuilds, a different type definition is being used, one which defines the return of setInterval and setTimeout to be
<number>
instead of<NodeJS.Timer>
. Obviously I can work around this, but seeing as these are standard functions in node and @types/node is a widely used type definition of the standard node library, it would probably be best to resolve this issue.I have created a very minimal example to demonstrate the problem.
How to Reproduce
npm install
oryarn install
webpack --watch
test.ts
. (I just added a newline and hit save)The text was updated successfully, but these errors were encountered: