express-engine-jsx
express-engine-jsx copied to clipboard
es import with node 13+
I want to start using es Import From, instead of common.js require(), but gets the this error:
`Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\Scrape\LM\Views\db.js require() of ES modules is not supported. require() of E:\Scrape\LM\Views\db.js from E:\Scrape\LM\node_modules\express-engine-jsx\require.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename db.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\Scrape\LM\package.json.
at new NodeError (node:internal/errors:329:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at requireJSX (E:\Scrape\LM\node_modules\express-engine-jsx\require.js:22:11)
at View.engine (E:\Scrape\LM\node_modules\express-engine-jsx\index.js:17:20)
at View.render (E:\Scrape\LM\node_modules\express\lib\view.js:135:8)
at tryRender (E:\Scrape\LM\node_modules\express\lib\application.js:640:10)
`
I am not using any builder (like Webpack)
For now it supports only require
. For now I don't have much time to add import ... from
, maybe on this weekend. I will notice you in this issue
Thanks. That will be appreciated!
@bugdriven try it out
I now get the following: var _layout = _interopRequireDefault(requireJSX("./layout", __dirname)); ^ ReferenceError: Cannot access 'requireJSX' before initialization
thanks for testing, fixed
Now I get: node:internal/modules/cjs/loader:1109 throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath); ^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\Scrape\LM\createLoader.js require() of ES modules is not supported. require() of E:\Scrape\LM\createLoader.js from E:\Scrape\LM\node_modules\express-engine-jsx\require.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename createScraper.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\Scrape\LM\package.json.
at new NodeError (node:internal/errors:329:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at requireJSX (E:\Scrape\LM\node_modules\express-engine-jsx\require.js:51:10)
at E:\Scrape\LM\Views\db.jsx:7:45
at Script.runInContext (node:vm:141:12)
at Script.runInNewContext (node:vm:146:17)
@bugdriven can you please go to node_modules\express-engine-jsx
and add to package.json
option "type": "commonjs",
it should say to your nodejs that my lib uses commonjs
style instead of yours module
style. If it will fix that error then I'll add it to repo.
That result in the following: (node:18088) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. E:\Scrape\LM\serve.js:1 import express from 'express' ^^^^^^
SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:355:18) at wrapSafe (node:internal/modules/cjs/loader:1022:15) at Module._compile (node:internal/modules/cjs/loader:1056:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10) at Module.load (node:internal/modules/cjs/loader:972:32) at Function.Module._load (node:internal/modules/cjs/loader:813:14) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) at node:internal/main/run_main_module:17:47
you changed your package.json
, I'm talking about node_modules\express-engine-jsx\package.json
.
Sorry about that...:) With that change I get the exact same error as the previous. FYI: don't know if this is relevant, but the createLoader.js is imported from db.jsx, and again imports other (es) modules.