Nuxt 2 server middleware : use import or require (or mix) ? #9892
Unanswered
dtoch
asked this question in
Questions (Nuxt 2)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Not a bug for me, but I've noticed using Nuxt 2.x that server middleware code mixing import and require does not fail.
For example if server-middleware/api.js is :
then it will execute the 4 hello() methods imported/required from the CJS/MJS modules.
However when running above directly using Node :
node server-middleware/api.js
then it will always fail with "Cannot use import statement outside a module" or "require is not defined" depending on whether "type": "module" or "type": "commonjs" was defined in package.json.
Is it a good idea to use a mix of import / require in the Nuxt server middleware or might it cause issues at one moment?
Remark : tested with Nuxt 2.15.2 on Node 12.22.5.
Beta Was this translation helpful? Give feedback.
All reactions