Open darkalor opened 4 years ago
Doesn't seem like it's the same issue. I don't have a problem with type files being picked up - its the actual sources that get missed.
I've also been unable to reproduce this when just running with ts-node
. The issue happens only with ts-node-dev
I experienced the same issue but recently after upgrade to "ts-node-dev": "^1.0.0-pre.55
and using the latest TypeScript 3.9.7
this seems to be gone.
I didn't realize that issue would be related, since it mentions issues appearing after 1.0.0-pre.44
, but I already had them on 44.
Updating to .55 and TS 3.9.7 did not resolve the issue for me.
It look like it works slightly better though - it seems to require only one restart now. Previously I had to do it 2-3 times sometimes.
Yeah, I've been in that boat too. Restarting for over 5 times sometimes before all files were correctly compiled. Usually I did this by hitting CTRL + S
a couple of times on the `index.ts
file.
This is indeed a very annoying issue... It gets better with every release but I feel there should be a test suite that verifies if all files are completely compiled when ts-node-dev
is done. Part of the issue is also that it doesn't happen for everyone. It's like on one OS/machine it does and the next one is fine, see my previous issue.
This is a hard one to tackle. Maybe @whitecolor could add some better/more detailed logging when running with the --debug
argument. It would allow for more detailed and accurate reports from users when things go wrong.
I've also been unable to reproduce this when just running with
ts-node
. The issue happens only withts-node-dev
Exactly my experience too
--debug
outputs all files being required and compiled, are your missing files not in this log, they are not being required?
@darkalor can you show the code of your index.ts
from example above.
--debug outputs all files being required and compiled, are your missing files not in this log, they are not being required?
It looks like files are not getting required, even though they're imported in the index. When I just restart ts-node-dev a couple of times on the exact same code it picks up more files in the list each time (see my original screenshots). It looks like it's not waiting for some async stuff perhaps, and just skips forward sometimes without getting everything compiled.
The behavior changed a bit with .55 - I'm getting a failure more consistently in the exact same spot now. I've also noticed that if I reduce the amount of imports it fails less often.
Here's how the index looks:
import dotenv from 'dotenv'
dotenv.config({ path: '../.env' })
import consoleStamp from 'console-stamp'
consoleStamp(console)
import express from 'express'
import { ApolloServer } from 'apollo-server-express'
import graphqlPlayground from 'graphql-playground-middleware-express'
import mongoose from 'mongoose'
import { typeDefs, resolvers } from './modules'
import * as auth from './auth'
async function main() {
try {
// Express
const app = express()
// Authentication
console.log(auth.authenticate) //<----------- this is where undefined prints in the error sceenshot
app.use('/graphql', auth.authenticate)
// GraphQL Playground
app.get('/playground', graphqlPlayground({ endpoint: '/graphql' }))
// MongoDB
const db = await mongoose.connect(process.env.MONGO_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
db && console.log('🍃 Connected to MongoDB')
// TODO: trying to catch issue with builds failing
console.log(typeDefs) // <-------- this one sometimes gives a bad result too
// Apollo Server
const server = new ApolloServer({
playground: false,
introspection: true,
typeDefs,
resolvers,
})
server.applyMiddleware({ app })
// Start Apollo Server
app.listen({ port: 8081 }, async () => {
console.log(
`🚀 Server ready at http://localhost:8081/playground`
)
})
} catch (err) {
console.error(err)
}
}
main()
And that's the error I get. It even says that it compiled auth.js
but the console log right after that prints it as undefined
@darkalor Just one stupid question here: are you certain that you don't need to do await auth.authenticate
? That is't not a promise? Just to be sure...
@DarkLite1 Nope it's not a promise. Besides if it was - the log would have printed that it's a promise.
@darkalor Is something wrong with deps required by auth
module? Maybe something wrong with its compilation?
for what it's worth, I came across this issue because I'm experiencing something similar where it will print eg:
[PEPPER] [INFO] 22:49:29 Restarting: src/redis/index.ts has been modified
[PEPPER] [DEBUG] 22:49:29 Removing all watchers from files
[PEPPER] [DEBUG] 22:49:29 Child is still running, restart upon exit
[PEPPER] [DEBUG] 22:49:29 Disconnecting from child
[PEPPER] [DEBUG] 22:49:29 Sending SIGTERM kill to child pid 52499
[PEPPER] [DEBUG] 22:49:29 Using tree-kill
[PEPPER] Child got SIGTERM, exiting.
[PEPPER] [DEBUG] 22:49:29 Child exited with code 0
But then the change will not be reflected - was trying with console.logs
, using tsnd --exit-child --tree-kill --respawn --debug --watch 'src/**/*.ts' src/index.ts
.
What is interesting is when I change the return
value of a function say, the change is picked up, tho the console.log is still there
I'm running some more tests around const a = 2; const b = 3; const c = a + b;
Maybe reproducable example?
@darkalor Is something wrong with deps required by
auth
module? Maybe something wrong with its compilation?
Apologies for the delayed response. No it's not related to the auth
module. Compilation can fail before or after that randomly.
Maybe reproducable example?
Can't share the project since it's work stuff, and just making a small example removes the problem (so I'm guessing it's dependent on the amount of dependencies). I'll try to think of something though
@darkalor I had the same problem for reproducing an example that demonstrates the problem. @samelie you seem to have a more simple examples, would you mind posting it here for further testing? Or a link to your GitHub?
Sry for absence. I believe the issue was the use of tsconfig-paths. Somehow the registering of modules was interfering. I tried every way to implement tsconfig-paths, but still this issue of changes not being applied.
The solution was to not use it. Things are working great now. If someone is using tsconfig-paths, there really is no need if you setup a yarn workspaces properly. This repo does this with ts
there really is no need if you setup a yarn workspaces properly.
Right. ts-config-paths
only add potential resolution issues. Though it was working for me for a while.
I encountered this issue exactly as you describe it today. It was working fine for the longest time, and then it suddenly stopped being able to resolve all the sources imported in the index file (there were no changes to the code or dependencies). Saving a couple of times to trigger a restart solves the problem and the code runs eventually. We are also using tsconfig-paths
, and it works for every member of the team except for me. I also tried running the code using a different machine, but I have the same issue there, both machines are running windows 10.
Running the code with ts-node works, as does nodemon.
Platform: Window 10 with WSL ts-node-dev version: 1.0.0-pre.44, also tried with 1.0.0-pre.52
Running into this really bizarre behavior - at first start tsnd can miss some files that have to be compiled. After doing a couple of restarts (without any changes, e.g. just by re-saving a file) it manages to pick up everything and works until the next time I re-run it.
Here's one complete fail at first run, doesn't pick up any files past
index
After a restart - a couple more files got picked up
One more restart - the module
Schema
only picks up two files, but should contain the same files as the moduleEvent