Closed giautm closed 2 years ago
I fixed by update the import statement:
- import extractFiles from 'extract-files'
+ import extractFiles from 'extract-files/extractFiles.mjs'
And declare ts module for it:
declare module 'extract-files/extractFiles.mjs' {
export default function extractFiles<T>(
values: any,
isExtractableFile?: (value: T) => boolean,
path: string = '',
)
}
also, require the custom File:
export class ReactNativeFile {
readonly uri: string
readonly name: string
readonly type: string
constructor({ uri, name, type }) {
this.uri = uri
this.name = name
this.type = type
}
}
const { clone, files } = extractFiles<ReactNativeFile>(
{
query: req.operation.text,
variables: req.variables,
},
(file) => file instanceof ReactNativeFile,
)
Glad you figured it out :)
And declare ts module for it
This should not be necessary, because the module has built in TypeScript types via JSDoc:
The TS compile in my project still complain about missing module. T_T
Maybe you need to update to a modern version of TypeScript that is capable of resolving .mjs
modules correctly. See TS config compilerOptions.module
value nodenext
:
https://www.typescriptlang.org/tsconfig#node12nodenext-nightly-builds
Maybe you need to update to a modern version of TypeScript that is capable of resolving
.mjs
modules correctly. See TS configcompilerOptions.module
valuenodenext
:
Thank you, let me try it. Currently, my app still cannot resolve the *.mjs module.
{
"compilerOptions": {
"target": "esnext",
"module": "ESNext"
}
}
I'm unable to use nodenext
for RN project. So, I think I have to downgrade to version 11. T_T
Ok, so I just learned something about TypeScript config after running into a similar weird problem in a project about certain module types being missing, even though it didn't make sense because the module was definitely there and the types can't be missing because they are inside the module as TypeScript JSDoc comments.
The fix was to set compilerOptions.maxNodeModuleJsDepth
to something higher than the 0
default, i.e. 10
. Otherwise TypeScript bails from type checking dependencies of dependencies, and instead of giving a relevant error it just spews an error beginning with TS7016: Could not find a declaration file for module
.
Here is the jsconfig.json
I'm using in projects now:
{
"compilerOptions": {
"maxNodeModuleJsDepth": 10,
"module": "nodenext",
"noEmit": true,
"strict": true
},
"typeAcquisition": {
"enable": false
}
}
Hello @jaydenseric, long time no talk. hehe.
I have an issue with
extract-files
today when I used it in the react-native when the metro bundling source code. It raises the error related to themain
field being missing in the package.jsonBecause the
main
field is missing so it using the default value asextract-files/index
but this file is not exists. Can you update it with a value?