if you place files in public folder with symbols * ( ) + and run node server.js in production you will get something like
/node_modules/next/node_modules/path-to-regexp/dist/index.js:80
throw new TypeError("Unbalanced pattern at " + i);
TypeError: Unexpected MODIFIER at 1, expected END
or
/node_modules/next/node_modules/path-to-regexp/dist/index.js:113
throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
^
This is bug with path-to-regexp. And it happens only in 9.1.5 after upgrade path-to-regexp from version 3 to 6.
Steps to reproduce the behavior, please provide code snippets or a repository:
1) npx create-next-app --example custom-server-express custom-server-express-app
or
yarn create next-app --example custom-server-express custom-server-express-app
2) Create public folder
3) Create any file with any symbol from * or ( or + . For example logo18+.png
4) Put that file in public folder
5) Run NODE_ENV=production node server.js
Route created for static svg -> server started
Fixed in 9.1.8-canary.11 -- please give it a try!
Solved my issue. Thanks @Timer.
It's fixed in 9.2.0 (canary was released)
I am using 9.3.6 and am seeing this when using + in routes for structures like this: /+/[slug]/index.js
same problem using koa line router.get('*', ...:
const Koa = require('koa');
const Router = require('koa-router');
const next = require('next');
const server = new Koa();
const router = new Router();
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
async function init() {
try {
await app.prepare();
router.get('/', async (ctx) => {
await app.render(ctx.req, ctx.res, '/home', ctx.query);
ctx.respond = false;
});
router.get('*', async (ctx) => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
});
server.use(router.routes());
server.listen(process.env.APP_PORT, () =>
console.info(`> Ready on ${process.env.APP_HOST} 馃殌`),
);
} catch (err) {
console.error(err);
}
}
init();
@markotom you should change usage of * in routes to (.*) or :splat* as per koajs/router v9 changelog.
Most helpful comment
@markotom you should change usage of
*in routes to(.*)or:splat*as per koajs/router v9 changelog.