'how to covert import from to require nodeJs
in my NodeJS project i tried to add expo SDK for notification but I have to use import while my all project using require I wont add type : module in package.json
I tried to change it like this but here is error
- import { Expo } from "expo-server-sdk";
+ const Expo = require("expo-server-sdk")
error if i use import
import { Expo } from "expo-server-sdk";
^^^^^^
SyntaxError: Cannot use import statement outside a module
the error if i use require
let expo = new Expo({ accessToken: process.env.EXPO_TOKEN });
^
TypeError: Expo is not a constructor
Solution 1:[1]
i get it now when i use require its point to the file so i want to call the Expo class
const expoObj = require("expo-server-sdk");
let expo = new expoObj.Expo({ accessToken: process.env.EXPO_TOKEN });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ahmed Elsayed |
