1

I have some issues on importing the express inside my nuxt project;

I have to use the express to make a login page but the express importing is relating the following problem:

 WARN  Compiled with 5 warnings                                                                                                                 friendly-errors 09:56:47


 WARN  in ./node_modules/express/lib/view.js                                                                                                    friendly-errors 09:56:47

Critical dependency: the request of a dependency is an expression                                                                               friendly-errors 09:56:47
                                                                                                                                                friendly-errors 09:56:47

 WARN  in ./node_modules/body-parser/node_modules/on-finished/index.js                                                                          friendly-errors 09:56:47

Module not found: Error: Can't resolve 'async_hooks' in '/home/joao/Documentos/projetos/metaseed/node_modules/body-parser/node_modules/on-finished'
                                                                                                                                                friendly-errors 09:56:47

 WARN  in ./node_modules/express/node_modules/on-finished/index.js                                                                              friendly-errors 09:56:47

Module not found: Error: Can't resolve 'async_hooks' in '/home/joao/Documentos/projetos/metaseed/node_modules/express/node_modules/on-finished' friendly-errors 09:56:47
                                                                                                                                                friendly-errors 09:56:47

 WARN  in ./node_modules/raw-body/index.js                                                                                                      friendly-errors 09:56:47

Module not found: Error: Can't resolve 'async_hooks' in '/home/joao/Documentos/projetos/metaseed/node_modules/raw-body'                         friendly-errors 09:56:47
                                                                                                                                                friendly-errors 09:56:47

 WARN  in ./node_modules/send/node_modules/on-finished/index.js                                                                                 friendly-errors 09:56:47

Module not found: Error: Can't resolve 'async_hooks' in '/home/joao/Documentos/projetos/metaseed/node_modules/send/node_modules/on-finished' 

This is how my code is set right now. I have already imported dotenv correctly but the express did not work;

export default () => {
  require('../node_modules/dotenv').config()
  const express = require('express')

  const app = express()
}

Note: I already tried to search for ('../node_modules/express') and the same problem appears

This is also my dependencies, I think it all correct

"dependencies": {
  "@nuxtjs/auth-next": "5.0.0-1667386184.dfbbb54",
  "@nuxtjs/axios": "^5.13.6",
  "bootstrap": "^4.6.2",
  "bootstrap-vue": "^2.22.0",
  "core-js": "^3.25.3",
  "fs": "^0.0.1-security",
  "net": "^1.0.2",
  "nuxt": "^2.15.8",
  "require": "^2.4.20",
  "vue": "^2.7.10",
  "vue-server-renderer": "^2.7.10",
  "vue-template-compiler": "^2.7.10"
},
"devDependencies": {
  "@vue/test-utils": "^1.3.0",
  "babel-core": "7.0.0-bridge.0",
  "babel-jest": "^29.1.2",
  "bcrypt": "^5.1.0",
  "dotenv": "^16.0.3",
  "express": "^4.18.2",
  "jest": "^29.1.2",
  "jest-environment-jsdom": "^29.1.2",
  "jsonwebtoken": "^8.5.1",
  "mongoose": "^6.7.2",
  "nodemon": "^2.0.20",
  "vue-jest": "^3.0.4"
}

Anyone knows what could be?

kissu
  • 40,416
  • 14
  • 65
  • 133
João Denari
  • 111
  • 1
  • 7
  • Env variables are already baked-in: https://stackoverflow.com/a/67705541/8816585 As for express, you should use `import` rather than `require` since we're doing modern code nowadays. Where are you doing your import also? And what version of Node are you using? – kissu Nov 10 '22 at 13:12
  • npm --version: 8.19.2 | node --version: v16.18.1 These are the node/npm version on my computer; "engines": {"node": ">=14.0.0"} this is what I found on my package.json. About your advise to use import i've tried this but the same problem comes: import express from '../node_modules/express'. My import is inside a folder called 'mainfolder/middleware' and the node_module is inside 'mainfolder/node_modules' – João Denari Nov 10 '22 at 14:16
  • Node version is fine! The middleware directory is used for client-side, where you cannot import `express` unfortunately. What do you need it for? – kissu Nov 10 '22 at 14:19
  • I try to make a auth/login into a nuxt project. I already did that in a node project, but never inside nuxt which I am kind a new; In my node auth project I used to use express, mongoose, bcrypt and jsonwebtoken. And basically I was trying to make the same logical inside nuxt – João Denari Nov 10 '22 at 14:29
  • maybe i am doing in the wrong folder, right? Is it not supposted to be inside middleware? – João Denari Nov 10 '22 at 14:30
  • Here is how to handle an express server in Nuxt2: https://stackoverflow.com/a/72102209/8816585 (Nuxt3 is far more powerful on that aspect) Nuxt does have some "Node.js" capabilities but it's not it's main focus/strength. In your case, you would be better having a separate Node server hosted somewhere or a serverless function. Here is a bit more context on how the (pure) server side can work in Nuxt2: https://stackoverflow.com/a/67689121/8816585 – kissu Nov 10 '22 at 14:34

0 Answers0