require is not defined in ES module scope after Build #35
Replies: 1 comment 4 replies
-
Hey @olegbelov21 Thanks for testing it on the Raspberry pi. I usually build it on my pc and copy the build results to the raspberry pi, and it seems there is a problem. As a quick fix, you could copy/move the build folder to another location and run the server from there.
Or you could remove the package.json after the build.
I will also add the port as a startup argument with the next release.
I'm not familiar with the ES module and know the pitfalls, especially with webpack. I'll try to find a solution. |
Beta Was this translation helpful? Give feedback.
-
Hello, everyone,
I wanted to try to compile the project myself on the Raspberry pi (because I wanted to change the port from 8000 to 80 in the file raspiCam/src/server/main.ts).
The project compiles:
but I get the following error when running node server.js
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/pi/projects/raspiCam/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at 3685 (file:///home/pi/projects/raspiCam/build/server.js:2:195430)
at i (file:///home/pi/projects/raspiCam/build/server.js:2:464533)
at file:///home/pi/projects/raspiCam/build/server.js:2:464895
at file:///home/pi/projects/raspiCam/build/server.js:2:484115
at file:///home/pi/projects/raspiCam/build/server.js:2:484119
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node.js v18.13.0
I have already tried deleting or changing "type": "module" in the package.json.
does anyone have an idea?
Best regards
Beta Was this translation helpful? Give feedback.
All reactions