我创建了一个新文件:
src
graphql
types
types.ts
types.ts中的内容:
export const marge = "marge";
但是当我尝试
import { marge } from "./graphql/types/types";
在index.ts
内部,我收到以下Web Pack错误:
ERROR in ./src/index.ts
Module not found: Error: Can't resolve './graphql/types/types'
Any idea why?
webpack.config.js
var path = require("path");
module.exports = {
entry: "./src/index.ts",
devtool: "inline-source-map",
output: {
path: path.resolve(__dirname, "build"),
filename: "bundle.js"
},
module: {
rules: [
{
use: "ts-loader",
test: /\.ts?$/
}
]
}
};
tsconfig.json
文件
{
"compilerOptions": {
"outDir": "./build/",
"noImplicitAny": true,
"target": "es5",
"sourceMap": true,
"allowJs": true,
"lib": ["es6"]
}
}
答案 0 :(得分:1)
弄清楚了-我不见了
resolve: {
extensions: ['.ts'] //resolve all the modules other than index.ts
},
在webpack配置中,因此仅解析了 index.ts ,而所有其他文件都被跳过了。