0

I am trying to use node fetch to retrieve a string from a Misty robot and then pass this information to a Lobe ML model for a senior year developmental class. The problem is that fetch was originally not defined. I then installed the package in the terminal and am now stuck at "Module import or export statement unexpected here" when I try to import the package in my file. I am super confused on how to solve this and have spent the last 3 class periods reading docs and other stack overflow posts and can not find anything that works for me. Does anyone have any tips?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • Can you post your code and the package.json file content? – Jordan Breton Oct 20 '21 at 17:22
  • Are you able to identify the module that fails the import? Please link the npm package as well as how you are importing the module. – Dan Oct 20 '21 at 21:04
  • package.json: { "name": "pkg", "version": "1.0.0", "description": "", "main": "MaskDetection.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "node-fetch": "^3.0.0", "uniq": "^1.0.1" } } – excitedrasin Oct 28 '21 at 15:36
  • import fetch from "node-fetch"; Promise.race([ fetch('http://10.1.100.216/api/cameras/rgb?base64=true&fileName=lol&width=1920&height=1080&displayOnScreen=false&overwriteExisting=true', { method: 'GET' }), new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 10000)) ]) – excitedrasin Oct 28 '21 at 15:39
  • @dan wdym by link the npm package? – excitedrasin Oct 28 '21 at 15:41
  • @excitedrasin Seeing how it's imported might help with debugging it. You can move some of the additional info to your question via edit. The import looks correct. I am assuming if you comment out the import the error is gone? If you are importing it into a browser environment then it may fail if it's not a node environment. If you can provide more complete demo that can be replicated it would help a lot. – Dan Oct 28 '21 at 18:31
  • @excitedrasin You may also want to check if the `import` syntax is working for you by creating a small `.js` file to test this. This question and their answer may be relevant to your issue: https://stackoverflow.com/questions/69041454/error-require-of-es-modules-is-not-supported-when-importing-node-fetch – Dan Oct 28 '21 at 18:36

0 Answers0