我很难让webpack建立我的档案。它只是吐出一堆错误,都是相同的形式,上面写着:
ERROR in ./node_modules/typescript-rest/dist/server.js
Module not found: Error: Can't resolve 'typescript-ioc/es6' in '/Users/Jack/NODE/ts-rest-session/node_modules/typescript-rest/dist'它似乎没有正确地加载node_modules。
tsc和ts-节点都能够很好地构建/运行项目。以下是我的心声:
tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "dom"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}webpack.config.js
module.exports = {
entry: {
server: './server.ts'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
modules: ["node_modules"]
extensions: ['.tsx', '.ts', '.js', '.json']
},
output: {
filename: '[name].bundle.js',
path: __dirname + 'dist'
}
};如果有人有任何想法,我会洗耳恭听的!我尝试从node_modules中删除module.rules中的排除项。
发布于 2018-07-26 05:34:45
如果您想根据baseUrl和tsconfig.json中的路径解析模块,那么可以使用tsconfig- paths webpack插件包。有关此功能的详细信息,请参阅模块解析文档。
这个特性需要webpack 2.1+和TypeScript 2.0+。使用下面的配置或检查包以获得有关使用的更多信息。
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
...
resolve: {
plugins: [new TsconfigPathsPlugin({ /*configFile: "./path/to/tsconfig.json" */ })]
}
...
}https://github.com/TypeStrong/ts-loader/blob/master/README.md
编辑
似乎你正在尝试为节点构建一些东西,默认情况下webpack为网络构建。所以你必须在你的webpack.config中设定正确的目标。此外,您还缺少一个",“内部的决心和输出路径应该类似于路径:__dirname + '/dist‘
我试图重现您的问题,这个配置对我来说很好:
var nodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'development',
entry: './server.ts',
// in order to ignore built-in modules like path, fs, etc.
target: 'node',
// in order to ignore all modules in node_modules folder
externals: [nodeExternals()],
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.json']
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
]
},
};https://stackoverflow.com/questions/51528562
复制相似问题