-
Type: Task
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Node.js, React Native
-
2 - S (<= 1 week)
-
6198
How frequently does the bug occur?
Always
Description
I need to use the Document class because I am creating a customize get collection function
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
export function getCollection<T extends Document>(user: User, collectionName: string, databaseName = MongoDatabaseName) { return user.mongoClient(MongoServiceName).db(databaseName).collection<T>(collectionName); }
This will raise an error TS2305: Module 'realm' has no exported member Document
Cause
The @realm did not export the Document type, but the realm package did. This causes the compiler to be unable to find the definition of Document type.
Workaround
I did find a workaround, by manually adding the realm package to the tsconfig.json, the compiler is able to find the type.
{"compilerOptions": { "paths": { "realm": ["./node_modules/realm/dist/bundle.d.ts"], } }}
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
- install all dependency
{ "name": "myawesomerealmapp", "version": "1.0.0", "scripts": { "start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios" }, "dependencies": { "@realm/react": "^0.6.1", "expo": "^49.0.8", "expo-dev-client": "~2.4.8", "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.4", "react-native-get-random-values": "~1.9.0", "realm": "^12.2.1" }, "devDependencies": { "@babel/core": "^7.22.5", "@babel/plugin-proposal-decorators": "^7.22.5", "@realm/babel-plugin": "^0.1.1", "@types/react": "~18.2.13", "typescript": "^5.1.3" }, "license": "Apache-2.0", "private": true }
- Create a file test.ts with the following code
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
import {Document} from 'realm'
Error will raise on the import line.
Version
"realm": "^12.2.1",, "@realm/react": "^0.6.0",
What services are you using?
Atlas App Services: Functions or GraphQL or DataAPI etc
Are you using encryption?
No
Platform OS and version(s)
Win11 23H2
Build environment
Which debugger for React Native: ..
Cocoapods version
No response