Error - Must use import to load ES Module

This topic was automatically generated from Slack. You can find the original thread here.

Nathan Roest : Hello all,

I keep getting this error message when trying to upload any files into Google Drive,
Has anyone run into this and have a solution to fixing it?

Thanks!

ErrorMust use import to load ES Module: /opt/ee/node_modules/got/dist/source/index.js require() of ES modules is not supported. require() of /opt/ee/node_modules/got/dist/source/index.js from /opt/ee/c_W3fz1Pl/index.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 /opt/ee/node_modules/got/dist/source/index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from /opt/ee/node_modules/got/package.json.

at Object.Module._extensions…js (internal/modules/cjs/loader.js:1102:13)
at Module.Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.Module.require (internal/modules/cjs/loader.js:974:19)
at null.require (internal/modules/cjs/helpers.js:92:18)
at Object.module.exports (/steps/upload_file_by_url.js:8:13)
at MessagePort.messageHandler (/opt/nodejs/node_modules/@pipedreamhq/execution-environment/launch_worker.js:447:41)
at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:399:24)
at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26)

Dylan Sather (Pipedream) : anywhere you see this line in your workflow:

const got = require("got")

could you replace it with

const { got } = await import("got")

We pull in the newest version of npm packages when you deploy a workflow, and the newest version of got changed the way you have to import it for use in your code.

Nathan Roest : great thanks alot for that! Makes complete sense and can confirm it’s working now

Dylan Sather (Pipedream) : great!