Skip to content
Back

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

  • 0
  • Web
Binyamin
26 Apr, 2023, 17:05

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

TL;DR
Title: [SOLVED] Syntax Error: The requested module does not provide an export named 'fetch' Solution: The error was resolved by changing the `node` version to `node16` or `nodenext`. Additionally, the `moduleResolution` value in the `tsconfig.json` file was changed to "bundler". The import statement in the TypeScript file was also updated to explicitly import the required modules from the `appwrite` package.
Rajiv
26 Apr, 2023, 17:05

I get the error in the browser console

Rajiv
26 Apr, 2023, 17:06

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

Binyamin
26 Apr, 2023, 17:06

I mean inside api package

Rajiv
26 Apr, 2023, 17:07

sure, just a sec

Rajiv
26 Apr, 2023, 17:07

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

Binyamin
26 Apr, 2023, 17:08

Can you try to change it to this

TypeScript
import {
  Client,
  Account,
  Databases,
  Teams,
  Functions,
  Storage,
  Avatars,
} from 'appwrite';
Binyamin
26 Apr, 2023, 17:08

And then run it?

Rajiv
26 Apr, 2023, 17:09

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

Binyamin
26 Apr, 2023, 17:11

It should work with your TypeScript as well

Binyamin
26 Apr, 2023, 17:11

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

Rajiv
26 Apr, 2023, 17:13

moduleResolution: 'bundler'

Rajiv
26 Apr, 2023, 17:15

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)

Binyamin
26 Apr, 2023, 17:15

That's because it tries to load the js file

Binyamin
26 Apr, 2023, 17:16

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

Binyamin
26 Apr, 2023, 17:16

This 👆

Rajiv
26 Apr, 2023, 17:16

Let me try that

Rajiv
26 Apr, 2023, 17:20

The import does not work with node16 but works with node 👍

Binyamin
26 Apr, 2023, 17:20

Good

Binyamin
26 Apr, 2023, 17:20

So is the error still appears?

Rajiv
26 Apr, 2023, 17:21

Thanks! The error does not appear anymore

Binyamin
26 Apr, 2023, 17:21

👍

Rajiv
26 Apr, 2023, 17:22

😃

Drake
26 Apr, 2023, 19:22

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

Drake
26 Apr, 2023, 19:22

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

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more