Error triggered using mailer and any template adapter combined with a custom webpack.config.js, reporting that dist/css_inline_bg.wasm not found.
wxk6b1203 opened this issue · 1 comments
wxk6b1203 commented
Describe the bug
When I use a custom webpack.config.js
to build the nestjs
bundle and start with node dist/main.js
, the app reports an error and exit immediately:
Error: ENOENT: no such file or directory, open 'C:\Users\xxx\Documents\Project\xxx-worker\dist\css_inline_bg.wasm'
at Object.openSync (node:fs:581:18)
at Object.readFileSync (node:fs:457:35)
at Object.__decorate (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:473906:54)
at __webpack_require__ (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:550543:42)
at Object.<anonymous> (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:472238:22)
at __webpack_require__ (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:550543:42)
at Object.<anonymous> (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:59790:23)
at __webpack_require__ (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:550543:42)
at Object.defineProperty.value (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:10:22)
at __webpack_require__ (C:\Users\xxx\Documents\Project\xxx-worker\dist\main.js:550543:42) {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\xxx\\Documents\\Project\\xxx-worker\\dist\\css_inline_bg.wasm'
}
This will happen if I use anyone of the template, e.g.:
MailerModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
transport: {
host: configService.get('MAIL_HOST'),
port: configService.get('MAIL_PORT'),
secure: !!configService.get('MAIL_SECURE') || false,
auth: {
user: configService.get('MAIL_USER'),
pass: configService.get('MAIL_PASS'),
},
},
+ template: {
+ dir: __dirname + '/template',
+ adapter: new EjsAdapter(),
+ },
defaults: {
from: '"No Reply" <gg>',
},
}),
}),
then create a webpack.config.js
:
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path");
const webpack = require("webpack");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
module.exports = {
entry: "./src/main",
target: "node",
// 置为空即可忽略webpack-node-externals插件
externals: {},
// ts文件的处理
module: {
rules: [
{
test: /\.ts?$/,
use: {
loader: "ts-loader",
options: { transpileOnly: true }
},
exclude: /node_modules/
}
]
},
// 打包后的文件名称以及位置
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist")
},
resolve: {
extensions: [".js", ".ts", ".json"]
},
plugins: [
// 需要进行忽略的插件
new webpack.IgnorePlugin({
checkResource(resource) {
const lazyImports = [
"@nestjs/microservices",
"@nestjs/microservices/microservices-module",
"@nestjs/websockets/socket-module",
"cache-manager",
"class-validator",
"class-transformer"
];
if (!lazyImports.includes(resource)) {
return false;
}
try {
require.resolve(resource, {
paths: [process.cwd()]
});
} catch (err) {
return true;
}
return false;
}
}),
new ForkTsCheckerWebpackPlugin()
]
};
and then modify package.json
:
"scripts": {
+ "build": "nest build --webpack --webpackPath=./webpack.config.js",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/jest/bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
and then
npm run build
If I run node dist/main.js
, the error is triggered.
Expected behavior
None of the errors should be printed.
Desktop (please complete the following information):
- OS: Windows 11 x64
- Node: v20.10.0
- NPM: 10.20.3
Additional context
If I remove the template, everything goes fine.
Stranger6667 commented
I am not sure how to fix it on the mailer
side, but if there is anything I can do from the css-inline
side, please, let me know.