Skip to content

Commit 5651fff

Browse files
committed
added package.json to priv specifying CJS type explicitly
In my Elixir project, I have package.json in a root directory. It specifies `type: module` as I'm writing JS in ESM syntax, with import / export. With that setup, nodejs treats `deps/nodejs/priv/server.js` as a project script, since it doesn't have package.json next to it. Exact error I'm getting: ``` 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 '/Users/user/project/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. ``` Adding package.json to priv simply explicitly informs nodejs that script is written in CJS.
1 parent 8b4e841 commit 5651fff

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

priv/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "elixir-nodejs",
3+
"type": "commonjs"
4+
}

0 commit comments

Comments
 (0)