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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...