While using import statements in my server.js file, I get the following error.
(event.js) error while parsing server file "'import' and 'export' may appear only with 'sourceType: module'"
(event.js) SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
The beginning of my server.js file looks like this…
import { franc } from 'franc';
import CloudStorage from './services/CloudStorage';
import OpenAI from './services/OpenAI';
While nodejs v18 officially supports ES modules, it seems like fdk is throwing these errors.
I am unable to use npm packages like franc, which are ESM-only modules, meaning they can’t be required in my server.js.
You will set "type": "module" in the package.json file within the server folder. Currently, developers don’t have access to that file.
I’m guessing that the fdk picks up the dependencies from manifest.json and constructs the package.json before npm installing all the dependencies.
Thanks for the inputs, @arunrajkumar235. Support for ES modules and the import and export statements have come up a few times now. We will work with our engineers to see if we can ship it.
Meanwhile, I don’t see a way to require() this module, as you have noted.