[英]tsconfig path and webpack alias - cannot find module issue
myCustom and ToDo are each react app and want to import MyCustom as a module inside ToDo app. myCustom 和 ToDo 都是 react 应用程序,并且希望将 MyCustom 作为 ToDo 应用程序中的模块导入。
so following was my trial / folder structure:所以以下是我的试用/文件夹结构:
[api]
|
[client]
|- [MyCustom]
|- [ToDo]
| |- [src] (in src, will use - import {} from 'myCustom')
| |- tsconfig.json (added "paths": { "myCustom": ["../myCustom/src"] })
| |- package.json (added dependency - "myCustom": "1.0.0")
and in ToDo app, when I try npm install
, it says myCustom
is not in the npm registry.在 ToDo 应用程序中,当我尝试
npm install
时,它说myCustom
不在 npm 注册表中。
can you point out what's wrong here, please?你能指出这里有什么问题吗?
_____________________________ _____________________________
on TODO webpack.config.js file, I've added在 TODO webpack.config.js 文件上,我添加了
resolve: {
modules: ['../MyCustom/src']
},
resolveLoader: {
modules: ['../MyCustom/src', 'myCustom']
}
and built failed with following error:并构建失败并出现以下错误:
Module not found: Error: Can't resolve 'source-map-loader'.找不到模块:错误:无法解析“source-map-loader”。
Am I using a loader wrong?我是否使用了错误的装载机?
resolve is a main topic in webpack.解决是 webpack 中的一个主要主题。
// https://github.com/unic/darvin-webpack-boilerplate/blob/master/webpack.config.js
const webpackConfigProd ={
resolve: {
modules: ['node_modules', '@yourAlias/yourCustomDir']
},
resolveLoader: {
modules: ['node_modules', '@yourAlias/loaderDir']
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.