nextjs app issue #5418
vasuneet
started this conversation in
Show and Tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to use customServer in nextjs app. So to do that i am providing
customerServerPath = path to server.js in my app
Server.js is as below :
import next from 'next';
import express from 'express';
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express()
//server.use('/','../../dist/apps/app-shell-ssr/.next/server')
server.get('/a', (req, res) => {
return app.render(req, res, '/a', req.query)
})
server.get('/b', (req, res) => {
return app.render(req, res, '/b', req.query)
})
server.all('*', (req, res) => {
return handle(req, res)
})
server.listen(port, (err) => {
if (err) throw err
console.log(> Ready on http://localhost:${port})
})
})
Giviing Error:
Cannot use import statement outside a module
If I use require instead of import
Giving Error:
require(...) is not a function.
Can you help here
Expected Behavior
No error should be reported in console and custom server should work fine.
nx build is working fine.
but when i try to run ng serve with custom server it gives error.
Steps to Reproduce
generate nextjs app using generator and use the mentioned server file.
Failure Logs
already provided details above
Environment
NX Report complete - copy this into the issue template
Node : 14.16.1
OS : darwin x64
yarn : 1.22.10
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 12.0.7
@nrwl/cypress : 12.0.7
@nrwl/devkit : 12.0.7
@nrwl/eslint-plugin-nx : 12.0.7
@nrwl/express : Not Found
@nrwl/jest : 12.0.7
@nrwl/linter : 12.0.7
@nrwl/nest : Not Found
@nrwl/next : 12.0.8
@nrwl/node : Not Found
@nrwl/react : 12.0.7
@nrwl/schematics : Not Found
@nrwl/tao : 12.0.7
@nrwl/web : 12.0.7
@nrwl/workspace : 12.0.7
@nrwl/storybook : 12.0.7
@nrwl/gatsby : Not Found
typescript : 4.1.5
package.json
{
"name": "app-shell-workspace",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"nx": "nx",
"start": "nx serve",
"build": "nx build",
"test": "nx test",
"lint": "nx workspace-lint && nx lint",
"e2e": "nx e2e",
"affected:apps": "nx affected:apps",
"affected:libs": "nx affected:libs",
"affected:build": "nx affected:build",
"affected:e2e": "nx affected:e2e",
"affected:test": "nx affected:test",
"affected:lint": "nx affected:lint",
"affected:dep-graph": "nx affected:dep-graph",
"affected": "nx affected",
"format": "nx format:write",
"format:write": "nx format:write",
"format:check": "nx format:check",
"update": "nx migrate latest",
"workspace-generator": "nx workspace-generator",
"dep-graph": "nx dep-graph",
"help": "nx help"
},
"private": true,
"dependencies": {
"@types/express": "^4.17.11",
"core-js": "^3.6.5",
"document-register-element": "1.13.1",
"express": "^4.17.1",
"next": "10.1.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"regenerator-runtime": "0.13.7",
"styled-jsx": "3.4.4",
"tslib": "^2.0.0"
},
"devDependencies": {
"@babel/core": "7.12.13",
"@babel/preset-env": "7.12.13",
"@babel/preset-react": "7.12.13",
"@babel/preset-typescript": "7.12.13",
"@nrwl/cli": "12.0.7",
"@nrwl/cypress": "12.0.7",
"@nrwl/eslint-plugin-nx": "12.0.7",
"@nrwl/jest": "12.0.7",
"@nrwl/linter": "12.0.7",
"@nrwl/next": "^12.0.8",
"@nrwl/react": "12.0.7",
"@nrwl/tao": "12.0.7",
"@nrwl/web": "12.0.7",
"@nrwl/workspace": "12.0.7",
"@testing-library/react": "11.2.6",
"@types/jest": "26.0.8",
"@types/node": "14.14.33",
"@types/react": "17.0.3",
"@types/react-dom": "17.0.3",
"@types/styled-jsx": "2.2.8",
"@typescript-eslint/eslint-plugin": "4.19.0",
"@typescript-eslint/parser": "4.19.0",
"babel-jest": "26.2.2",
"cypress": "^6.0.1",
"dotenv": "8.2.0",
"eslint": "7.22.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-react": "7.23.1",
"eslint-plugin-react-hooks": "4.2.0",
"jest": "26.2.2",
"prettier": "2.2.1",
"ts-jest": "26.4.0",
"ts-node": "~9.1.1",
"typescript": "~4.1.4"
}
}
Beta Was this translation helpful? Give feedback.
All reactions