th0rgall posted a new question
express-template •
This is related to nuxt universal mode in general: I couldn't find a good template.
Context: I'm maintaining a Nuxt app. I'm in the process of upgrading it from Nuxt v1.4.1 (2y old) to v2.14; and from node v8 to node v14.
Issue: the app relies on external blog post resources that can not be fetched on every request. Therefore they are loaded into an in-memory cache (which takes about 2 minutes).
In Nuxt v1.4.1 & node 8; the cache was a simple variable in the root scope of an "api.js" file that is imported into store/index.js
and called from nuxtServerInit
. The behavior was that this variable remained intact across requests, making it possible to use it as a simple "cache".
In Nuxt v2; the variable (whole root scope) gets re-defined / refreshed on every request. It can't be used as a cache anymore.
Here is a simple demonstration in CodeSandbox: https://codesandbox.io/s/aged-bash-nstc0?file=/store/index.js. See store/index.js (the only added code) & the server terminal. When visiting the app in the browser multiple times; the counter won't go higher than 1 (why does it even reach 1?)
I want to understand why this occurs, or why this behavior changed from Nuxt 1.4 => Nuxt 2.14. My hunch is that it is related to webpack changes. It would be great to still find a solution where the variable can be shared in Nuxt 2.14.
I tried: putting the cache in a node's global
property to no avail: that also got "refreshed"
This seems to be the exact same question: https://github.com/nuxt/nuxt.js/issues/7224
Disclaimer: I know that sharing state across requests in memory a bad practice. At the very least, it is not scalable across processes. But it is unlikely that the project needs to be scaled any time soon. I'm considering using redis now; which seems overkill compared to the previous solution that worked well for 2 years.
payalord posted a new question
express-template •
Starting from file api/index.js
, where express server begins and nuxt serverMiddleware setup, all import paths with '@' cannot find that path/files to import. Here are the error in console:
ERROR Cannot find module '@/api/routes/users'
What I need is for '@' to point to project root dir so i can include my custom js files from there, from any file that will be used in this server middleware including itself. My code of api/index.js
:
import express from 'express'
import users from '@/api/routes/users'
const app = express()
// Import API Routes
app.use(users)
// Export the server middleware
module.exports = {
path: '/api',
handler: app
}
JamesBurgoon posted a new bug report
express-template •
https://codesandbox.io/s/x56qv
NPM run dev
✔ Client
Compiled successfully in [n]s
✖ Client
Compiled with some errors in 1.57s
Module build failed (from ./node_modules/eslint-loader/index.js): friendly-errors 11:09:23
TypeError: Cannot read property 'eslint' of undefined
nuxt.config.js
build needs to be updated per: https://github.com/nuxt/nuxt.js/issues/3216#issuecomment-380777572
Gedminas posted a new bug report
express-template •
create empty project, try to run prod with express template
it to work
it returns
Cannot GET /
Somehow it cannot get .nuxt files if the files are built prior. It is still working with dev environment
was working with 4.5 nuxt
Gedminas posted a new question
express-template •
it returns
Cannot GET /
Somehow it cannot get .nuxt files if the files are built prior. It is still working with dev environment
core01 posted a new question
express-template •
Hello, after the release v2.4.0 Nuxt has TypeScript support. Is there any example of implementation TypeScript Express and nuxt?
It is not clear to me how to use TypeScript with express-template, particularly on server side, because express-example uses nodemon and requires nuxt.config.js in server/index.js file.
Thank you!
gp15237125756 posted a new question
express-template •
When I execute yarn start after installing dependencies,this error emerge. Also the error file is client.js. I guess babel is mandatory here to resolve the file.So I changed the devDependencies in package.json as below .
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-core": "6.26.0",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "7.1.2",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "6.24.1",
"eslint": "^4.3.0",
"eslint-config-standard": "^10.2.1",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^3.1.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
}
then the error disappeared.
My environment is windows 7 & node 8.11.1.
lanbau posted a new question
express-template •
demo link is down
Jonham posted a new question
express-template •
✖ error Error: Module parse failed: Unexpected token (93:4)
You may need an appropriate loader to handle this file type.
|
| },
> ...App
| };
| const next = ssrContext ? ssrContext.next : location => app.router.push(location); // Resolve route
at Object../.nuxt/index.js (server-bundle.js:97:7)
at __webpack_require__ (server-bundle.js:21:30)
at Module../.nuxt/server.js (server-bundle.js:130:64)
at __webpack_require__ (server-bundle.js:21:30)
at Object.0 (server-bundle.js:392:18)
at __webpack_require__ (server-bundle.js:21:30)
at module.exports../.nuxt/index.js (server-bundle.js:85:18)
at Object.<anonymous> (server-bundle.js:88:10)
at evaluateModule (/Users/jonham/code/part/get-web-pc/node_modules/vue-server-renderer/build.js:8349:21)
at /Users/jonham/code/part/get-web-pc/node_modules/vue-server-renderer/build.js:8407:18
at new Promise (<anonymous>)
at /Users/jonham/code/part/get-web-pc/node_modules/vue-server-renderer/build.js:8399:14
at Object.renderToString (/Users/jonham/code/part/get-web-pc/node_modules/vue-server-renderer/build.js:8575:9)
at Renderer.renderRoute (/Users/jonham/code/part/get-web-pc/node_modules/nuxt/dist/nuxt.js:2074:41)
at Renderer.nuxtMiddleware (/Users/jonham/code/part/get-web-pc/node_modules/nuxt/dist/nuxt.js:1629:31)
at call (/Users/jonham/code/part/get-web-pc/node_modules/connect/index.js:239:7)
at next (/Users/jonham/code/part/get-web-pc/node_modules/connect/index.js:183:5)
at next (/Users/jonham/code/part/get-web-pc/node_modules/connect/index.js:161:14)
at SendStream.error (/Users/jonham/code/part/get-web-pc/node_modules/serve-static/index.js:121:7)
at emitOne (events.js:116:13)
at SendStream.emit (events.js:211:7)
at SendStream.error (/Users/jonham/code/part/get-web-pc/node_modules/serve-static/node_modules/send/index.js:270:17)
fewiki posted a new question
express-template •
After update to v2.2.0, the example https://nuxtjs.org/api/nuxt-render/ doesnot work on express
But it works ok on nuxt-edge . More info: https://cmty.app/nuxt/nuxt.js/issues/c7985
fewiki posted a new question
express-template •
After update to v2.2.0, the example https://nuxtjs.org/api/nuxt-render/ doesnot work on express
But it works ok on nuxt-edge . More info: https://cmty.app/nuxt/nuxt.js/issues/c7985
thaycacac posted a new question
express-template •
I try to deploy my website to netlify but not successful. It seems impossible to execute the command
npm run generate
TheGitPanda posted a new question
express-template •
Since Webpack 4, there seems to be an issue with this project. I've been following the documentation on the readme.
When running npm run dev
an error about eslint-loader is showing. It seems nuxt is still installing Webpack 4 and leads me to believe its throwing all the dependencies into version warns and out of whack.
Further to tweaking to try and fix myself, Ive attempted:
But pussyfooting around with more errors. Theoretically this should just work, right?
nugrahawahyu posted a new question
express-template •
Nothing to preview
horihiro posted a new question
express-template •
Hi,
I tried to run this template on Azure Web Apps.
But it was failed.
I found that the issue is caused by the Web Apps architecture (e.g. using iisnode and Named Pipe, and restriction of connection to 'localhost' ).
Especially, named pipe (and unix pipe) is not supported by latest(1.4.2) of nuxt.js.
It will be supported from this commit of 2.x.
Do you have any plans to change version of nuxt.js?
F.Y.I.
I published two repositories.
horihiro/nuxt.js is forked from v1.4.2 of nuxt.js to add support of named pipe.
horihiro/nuxt-express-azure-webapps is generared by this template, and is added some commits to run on Azure WebApps.
JkmAS posted a new question
express-template •
Hi,
I am using nuxt-edge
with express
server via nuxt.config.js serverMiddleware
and I want to use aliases (~
, ~~
) in imports in the same way as on the frontend (e. g. in vue templates).
Is it even possible to use them? Because in this repo they are not used https://github.com/nuxt-community/express-template/blob/master/template/api/index.js#L7.
Thanks
If I use alias, the nuxt throws an error Cannot find module '~/router/router'
.
Works: import router from './router/router';
Doesn't work import router from '~/router/router';
express.js index file
'use strict';
import express from 'express';
import bodyParser from 'body-parser';
import router from '~/router/router';
import log from '~/helpers/logger';
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(router);
// catch pm2 shutdown signal
process.on('SIGINT', () => {
log.info('Service graceful shutdown');
});
export default {
path: '/api',
handler: app
};
nuxt.config.js
export default {
rootDir: __dirname,
router: {
middleware: 'lang'
},
// server api
serverMiddleware: ['~/server/index.js'],
axios: {
browserBaseURL: '/'
},
modules: [
'@nuxtjs/axios',
'@nuxtjs/pwa'
]
]
};
d3l3rium1986 posted a new question
express-template •
Just a quick question hopefully. Since the ExpressJS changes and removal of Backpack, there is no longer a Build/main.js to point to. Most of our apps end up with going through Plesk using Passenger which require an entry point which I can seem to work out since the changes. Hope that makes sense, cheers
foadyousefi posted a new question
express-template •
I'm using this template for a while and every thing was OK. The setup is like this:
for authentication on the server, I'm using passport and express-session.
In the nuxtServerInit
, I was trying to check if user is authenticated:
if (req.isAuthenticated())
After updated the app to use the new approach of setting server as serverMiddleware, now the nuxt app don't have access to req.session
or req.isAuthenticated()
. Basically it don't have access to server req
object and for checking if user authenticated, I've created an api endpoint and in the nuxtServerInit
, sending an api request and getting user object.
Other stuff like accessing authenticated router endpoints on the server is working perfectly.
After lots of googling, was not able to find any solutions. Not sure if this is issue or does it suppose to be like that.
Note: The README is still not updated for the latest changes. For example it still mentions backpack
have been used, but it is removed.
jingxinxin posted a new question
express-template •
What needs to be configured?
Can you give an example?
Please
thearabbit posted a new question
express-template •
Could example to use Mongodb
in this?