-
Notifications
You must be signed in to change notification settings - Fork 7
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
npm build and npm test in functions directory both fail due to type errors #3
Comments
I had to switch the build and test ts config files around due to the way the firebase deploy script expects the build to be tsconfig.json to be the main one, and then added some stuff to get it to transpile the .ts into .js via babel:
So we will need something similar to run before testing which converts the .ts to .js since this is no longer being done by typescript due to the need for babel to get some "advanced features" like the decorators used by the sparkson library. Also the tests will fail due to the security rules in firestore.rules as well but we can sort that out next once everyone has finished migrating to the REST end point. |
I don't think the issue is in .ts to .js conversion, it's that in your dependency tree you have multiple libraries (jest and mocha) specifying the same type name differently. I would suggest remove mocha & chai dependencies and just add jest since afaik jest includes its own equivalents of those libraries already. |
@miridius Do you still have this issue ? So on my side I can build and run the test ok. It was just the test script in package.json should point to |
@inmyth I still have the exact same issues. Steps taken:
Results:
Note: I can get the build working by uninstalling @types/mocha but then of course the tests fail even worse because they need those types. There must be some transitive dependency which includes @types/jest and that is clashing with @types/mocha |
Never mind I figured it out... @types/jest was in my user node_modules directory... I guess I installed something globally by accident. |
Work around having mocha and jest installed at the same time. This description is from https://stackoverflow.com/questions/55680391/typescript-error-ts2403-subsequent-variable-declarations-must-have-the-same-typ You can't put together mocha (and other test runners that use mocha, such as web-test-runner) together in the same module. Types can be defined only once, and mocha and jest declare a series of globals (needed so that they can be used directly without importing) which are incompatible with each other. You need to commit to one or the other, or if you use things such as web-test-runner or electron-mocha just choose another runner (cypress will do, for instance). The fix is taken from covidwatchorg/covidwatch-cloud-functions#3 Add the following property to the tsconfig file "compilerOptions": { "skipLibCheck": true }, This tells TypeScript that we want to skip the type checking of libraries in the node_modules folder. This saves compilation time and stops conflicting types in node modules from breaking the build. See https://www.typescriptlang.org/tsconfig#skipLibCheck
When I try to run
npm build
ornpm test
in the functions directory, I get errors like these:The text was updated successfully, but these errors were encountered: