gpt4 book ai didi

node.js - 后端 API 服务器 Typescript/Webpack 版本 : Module not found: Error: Can't resolve

转载 作者:太空宇宙 更新时间:2023-11-04 03:05:11 27 4
gpt4 key购买 nike

我在构建 TS 应用程序时收到错误列表。我猜它们是 Webpack 错误,但我不知道如何解决它们......

ERROR in ./~/errorhandler/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/errorhandler'

ERROR in ./~/serve-favicon/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/serve-favicon'

ERROR in ./~/etag/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/etag'

ERROR in ./~/express/lib/request.js
Module not found: Error: Can't resolve 'net' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/express/lib'

ERROR in ./~/express/lib/view.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/express/lib'

ERROR in ./~/send/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/send'

ERROR in ./~/destroy/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/destroy'

ERROR in ./~/mime/mime.js
Module not found: Error: Can't resolve 'fs' in '/Users/yves/Developments/IDEALCOMS/project/api_cockpit/node_modules/mime'

webpack.config.common.js

var webpack = require('webpack');

module.exports = {
entry: {
'app': './src/index.ts'
},

resolve: {
extensions: ['.js', '.ts']
},

module: {
loaders: [
{
test: /\.ts$/,
loaders: 'ts-loader'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.css$/,
loader: 'raw-loader'
}
]
},
plugins: []
};

webpack.config.dev.js

const path = require('path');

var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var commonConfig = require('./webpack.config.common.js');

var env = require('./env.json');

module.exports = webpackMerge(commonConfig, {

devtool: 'cheap-module-eval-source-map',

output: {
path: path.resolve(__dirname, 'dist'),
publicPath: "/js/app/",
filename: 'bundle.js',
chunkFilename: '[id].chunk.js'
},

plugins: []

});

更新 =============================

阅读博客文章后我找到了解决方案:Backend Apps with Webpack

webpack.config.dev.js

const path = require('path');
var fs = require('fs');

var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var commonConfig = require('./webpack.config.common.js');

var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});

module.exports = webpackMerge(commonConfig, {

devtool: 'cheap-module-eval-source-map',

output: {
path: path.resolve(__dirname, 'build'),
filename: 'backend.js',
chunkFilename: '[id].chunk.js'
},
externals: nodeModules,

plugins: [
new webpack.IgnorePlugin(/\.(css|less)$/),
new webpack.BannerPlugin('require("source-map-support").install();',
{ raw: true, entryOnly: false })
]

});

最佳答案

看来你必须在 webpack 配置文件中提及 target

试试这个

目标:' Node ',

将以上行添加到您的 webpack 配置文件中。上面的配置选项告诉 webpack 不要触及任何内置模块。

关于node.js - 后端 API 服务器 Typescript/Webpack 版本 : Module not found: Error: Can't resolve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43064469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com