So you'll have something like that
...
"version": "1.0.0",
"description": "",
"type": "module",
"main": "src/index.js",
...
ok I'll try that
Also you can change the second line to
const sdk = require("node-appwrite");
const { parseBuffer } = require("music-metadata");
But both solutions will do just fine
But according to music-metadata package:
The JavaScript in runtime is compliant with ECMAScript 2017 (ES8). Requires Node.jsยฎ version 6 or higher.
Yes I saw
is it still working?
Is this fixed the problem?
unfortunately , it doesnt work this is the new error I got:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/code-start/src/index.js
require() of ES modules is not supported.
require() of /usr/code-start/src/index.js from /usr/local/src/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/code-start/package.json.
Yes, sorry You need also to change the first line Try change the first line to this and test and lmn
import sdk from "node-appwrite";
import { parseBuffer } from "music-metadata";
And I try this also this is the error I got:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/code-start/src/index.js
require() of ES modules is not supported.
require() of /usr/code-start/src/index.js from /usr/local/src/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/code-start/package.json.
okok I'll try this one
Good
Yes, a bit confusing What I meant is if you change to this code
const sdk = require("node-appwrite");
const { parseBuffer } = require("music-metadata");
Then you need to remove the type:"module"
does not work
I think I am going to downgrade the pagkage
Have you try that? What error you got?
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/code-start/src/index.js
require() of ES modules is not supported.
require() of /usr/code-start/src/index.js from /usr/local/src/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/code-start/package.json.
And you change all the require to import?
finally its work I just downgrade the package
anyways thank you for your time to assist me
god bless
๐
i want to use ES modules, i inserted type: module in package js, and changed all require to import statements, but still get the "Must use import to load ES" as above @Binyamin
Please create a new topic in https://discord.com/channels/564160730845151244/1072905050399191082 with you issue
[SOLVED] Type module in node js clound function
Recommended threads
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Appwrite Functions cold start
Hello. I'm seeing really long cold starts on Appwrite Cloud Functions and wanted to know if this is expected. My function just authenticates the user, fetches ...
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...