Javascript Webpack ProvidePlugin无法解析到我的模块的绝对路径

Javascript Webpack ProvidePlugin无法解析到我的模块的绝对路径,javascript,webpack,path,filepath,webpack-provide-plugin,Javascript,Webpack,Path,Filepath,Webpack Provide Plugin,我试图使用Webpack ProvidePlugin使模块全局可用,但在尝试编译和/或运行项目时遇到路径解析错误。以下是相关文件: 我的服务 /home/me/workspace/my project/src/client/services/my service.js export default class { constructor() doSomething() { /* ... */ } } export default { initialize() {

我试图使用Webpack ProvidePlugin使模块全局可用,但在尝试编译和/或运行项目时遇到路径解析错误。以下是相关文件:


我的服务

/home/me/workspace/my project/src/client/services/my service.js

export default class {
   constructor()
   doSomething() { /* ... */ }
}
export default {
    initialize() {
        MyService.doSomething();
    }
}
new webpack.ProvidePlugin({
    'MyService': [path.resolve(path.join(__dirname, 'src/client/services/my-service.js')), 'default']
})

使用MyService的应用程序

/home/me/workspace/my project/src/client/app.js

export default class {
   constructor()
   doSomething() { /* ... */ }
}
export default {
    initialize() {
        MyService.doSomething();
    }
}
new webpack.ProvidePlugin({
    'MyService': [path.resolve(path.join(__dirname, 'src/client/services/my-service.js')), 'default']
})

网页包配置

/home/me/workspace/my project/webpack.config.js

export default class {
   constructor()
   doSomething() { /* ... */ }
}
export default {
    initialize() {
        MyService.doSomething();
    }
}
new webpack.ProvidePlugin({
    'MyService': [path.resolve(path.join(__dirname, 'src/client/services/my-service.js')), 'default']
})

构建项目时,Webpack会在
myproject/dist/bundle.js

构建我的项目进展顺利,但启动它会产生以下错误:

未找到模块:错误:无法在“/home/me/workspace/my project/dist/src/client/services/my service.js”中解析“/home/me/workspace/my project/src/client”

如果需要,后面会有更多的错误

我希望我的Webpack配置能够解析到
MyService
的绝对路径,并在遇到模块时在该绝对路径中进行sub。但奇怪的是,它似乎使用了相对于引用模块的文件目录的绝对路径。我很困惑

谢谢你的帮助