#[SOLVED] Syntax Error: The requested module does not provide an export named 'fetch'

1 messages ยท Page 1 of 1 (latest)

earnest cairn
#

Hello, I'm running a React TypeScript project with the appwrite sdk installed. When I import the module containing the appwrite setup, I get the following error:
Uncaught SyntaxError: The requested module '/node_modules/cross-fetch/dist/browser-ponyfill.js?v=6461ce81' does not provide an export named 'fetch' (at sdk.js?v=6461ce81:2:10)

I'm guessing it has to do with how modules are being resolved? Any help appreciated ๐Ÿ™‚

cedar bough
#

Can you share the way you inserted it in the code?

earnest cairn
#

I setup appwrite similar to how it's done in the react-todo-template.

As for using it in my code:

<FormProvider methods={methods} onSubmit={handleSubmit(async (data) => { await api.provider().local.clear(); await api .provider() .account.createEmailSession(data.email, data.password); })} >

cedar bough
#

Is it React with Next or something or pure frontend?

earnest cairn
#

This is in React

#

With TypeScript

#

Even when the api module has not been used after an import - it crashes the app

cedar bough
#

How do import the package?
Where do you get the error, in the browser?

earnest cairn
#

I get the error in the browser console

#

I am importing the package as a default import:
import api from '@/lib/appwrite';

cedar bough
#

I mean inside api package

earnest cairn
#

sure, just a sec

#

import { Client, Account, Databases, Teams, Functions, Storage, Avatars, } from 'node_modules/appwrite';

cedar bough
#

And then run it?

earnest cairn
#

The above works for JavaScript files but it does not resolve the import in TypeScript files

cedar bough
#

It should work with your TypeScript as well

#

What is the value of moduleResolution within your tsconfig.json file?

earnest cairn
#

moduleResolution: 'bundler'

#

I'll share the TS error below:

Could not find a declaration file for module 'appwrite'. '/Users/rajiv/Development/xxx/node_modules/appwrite/dist/esm/sdk.js' implicitly has an 'any' type. There are types at '/Users/rajiv/Development/xxxxx/node_modules/appwrite/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'appwrite' library may need to update its package.json or typings.ts(7016)

cedar bough
#

That's because it tries to load the js file

#

Can you try to change to either node or nodenext and then you should be able to load the file as I've mentioned before

earnest cairn
#

Let me try that

#

The import does not work with node16 but works with node ๐Ÿ‘

cedar bough
#

Good

#

So is the error still appears?

earnest cairn
#

Thanks! The error does not appear anymore

cedar bough
#

๐Ÿ‘

earnest cairn
#

๐Ÿ˜ƒ

honest salmon
#

[SOLVED] Syntax Error: The requested module does not provide export fetch