Pitfalls of Upgrading Midway from v6 to v8
Table of Contents
- this.ctx.render method does not exist
- TypeError: require(…).startCluster is not a function
- start error: EROFS: read-only file system, mkdir ‘/home’
- Config file issues
- Fatal JavaScript invalid size error
- Remove @ali/node-scripts dependency
- Manually add logger dependency
this.ctx.render method does not exist
During the upgrade process, you may find that the this.ctx.render method is unavailable. This is because, by default, Midway v8 no longer automatically enables the view rendering feature.
Solution
- Install the
@midwayjs/view-nunjucksplugin:npm install @midwayjs/view-nunjucks --save - Enable the view plugin in
src/configuration.ts:import * as webFramework from '@midwayjs/web'; import { join } from 'path'; import { Configuration } from '@midwayjs/decorator'; import * as view from '@midwayjs/view-nunjucks'; @Configuration({ imports: [webFramework, view], importConfigs: [join(__dirname, './config/')], }) export class AutoConfiguration {} - Configure Nunjucks in
src/config/config.default.ts:export const view = { defaultViewEngine: 'nunjucks', mapping: { '.nj': 'nunjucks', }, };
TypeError: require(…).startCluster is not a function
When running the project, you may encounter the following error:
TypeError: require(...).startCluster is not a function
Solution
Remove the @ali/midway-bin dependency:
npm uninstall @ali/midway-bin
start error: EROFS: read-only file system, mkdir ‘/home’
When starting the project, the following error may occur:
Error: EROFS: read-only file system, mkdir '/home'
Solution
Remove onelog-related code or dependencies. For example, comment out the imports and configurations related to onelog in src/configuration.ts.
Config file issues
After the upgrade, some export methods in the config file may no longer be compatible. For example, export const development might cause issues.
Solution
Remove export const development and define the configuration items directly in config.default.ts. For example:
export default {
keys: 'your-secret-key',
// other configurations...
};
Fatal JavaScript invalid size error
When running the project, you may encounter the following error:
Fatal error in , line 0
Fatal JavaScript invalid size error 169220804
Solution
This issue is usually related to the Node.js version or memory limits. You can try the following methods:
- Upgrade Node.js to the latest stable version.
- Increase the Node.js memory limit:
node --max-old-space-size=4096 your-entry-file.js
Remove @ali/node-scripts dependency
During the upgrade process, @ali/node-scripts may cause compatibility issues.
Solution
Remove the @ali/node-scripts dependency:
npm uninstall @ali/node-scripts
Manually add logger dependency
According to the Midway Official Blog, after upgrading to v8, you need to manually add logging-related dependencies.
Solution
Install @midwayjs/logger:
npm install @midwayjs/logger --save
Then, import and configure the logger module in src/configuration.ts:
import * as logger from '@midwayjs/logger';
@Configuration({
imports: [logger],
})
export class AutoConfiguration {}
Summary
During the upgrade to Midway v8, you may encounter various issues. This article summarizes common pitfalls and their solutions, including view rendering, dependency conflicts, and configuration file adjustments. It is recommended to carefully read the official documentation and test each module’s functionality step-by-step before upgrading to ensure the project’s stability.
References
- Midway.js Documentation — Official Midway.js framework documentation
- Node.js LTS Schedule — Official Node.js release schedule and LTS information
- Migrating to ESM — sindresorhus — Guide to migrating Node.js projects between module systems
Be the first to know when I post cool stuff
Subscribe to get my latest posts by email.
Thanks for signing up! Check your email to confirm your subscription.
Whoops, we weren't able to process your signup.