I have started to get cannot use import statement outside a module errors all of a sudden when adding code to my backend and now it is asking to change the style of my imports from what it was before.
I have seen other questions where it recommends upgrading node however as I have had previously ran into errors with newer versions and version 12.13 was previously problem free I don't want to change it again.
What is likely to have caused this problem? Would I be best removing new code?
The code I have added was from a MongoDB exmaple using mongoose whereas I my app is using Sequelize and Postgres.
\user.controller.js:3 import errorHandler from "../helpers/dbErrorHandler"; ^^^^^^ SyntaxError: Cannot use import statement outside a module //previous code in file exports.siteAdminLevel = (req, res) => { res.status(200).send("Site admin content."); }; // new code in file exports.userByID = async (req, res, next, id) => { try { let user = await user.findById(id).populate('following', '_id name') .populate('followers', '_id name') .exec() if (!user) return res.status('400').json({ error: "User not found" }) req.profile = user next() } catch (err) { return res.status('400').json({ error: "Could not retrieve user" }) } } https://stackoverflow.com/questions/66837540/getting-cannot-use-import-statement-outside-of-a-module-errors-and-dont-want March 28, 2021 at 08:59AM
没有评论:
发表评论