require is not defined in node.js 14.4.0

89 views
Skip to first unread message

Matthew Hamilton

unread,
Jun 7, 2020, 12:34:00 PM6/7/20
to nodejs
node.js 14.4.0 macOS Catalina, Visual Studio Code debugging. Line 11 in my app.mjs file is var FileSystem = require('fs'); The debugger throws "require is not defined" error on this line. Comment this line out and the debugger throws an error on line 23 which is var PDFImage = require('pdf-image'). the pdf-image package is installed. I'm not sure what is going on. The only help I can find is about require not working in a browser. I AM NOT RUNNING IN A BROWSER. I AM RUNNING IN NODE.JS. Thank you!

John Shaver

unread,
Jun 7, 2020, 5:51:28 PM6/7/20
to nod...@googlegroups.com
In an .mjs file, you do not use require.  You use import.  Try: 

import fs from "fs";

More info:

-John

On Sun, Jun 7, 2020, 9:33 AM Matthew Hamilton <buddh...@gmail.com> wrote:
node.js 14.4.0 macOS Catalina, Visual Studio Code debugging. Line 11 in my app.mjs file is var FileSystem = require('fs'); The debugger throws "require is not defined" error on this line. Comment this line out and the debugger throws an error on line 23 which is var PDFImage = require('pdf-image'). the pdf-image package is installed. I'm not sure what is going on. The only help I can find is about require not working in a browser. I AM NOT RUNNING IN A BROWSER. I AM RUNNING IN NODE.JS. Thank you!

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/6ede6143-eb84-4678-9d36-269feae52b62o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages