webpack config不能与node.js中的require()一起使用

时间:2016-09-27 10:14:44

标签: javascript node.js reactjs webpack

我有像这样的文件调用abc.jsx

var MyTitle = require('./MyTitle')

but I have to do require('./MyTitle)

因为我运行webpack它给我错误。

ERROR in ./js/MyTitle.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ./MyTitle in /Users/username/Documents/intro-to-react/js
 @ ./js/MyTitle.jsx 5:14-34

1 个答案:

答案 0 :(得分:0)

您应该设置webpack配置以使用babel-loader解析jsx文件。模块加载器中的以下行@Bean public MappedInterceptor myInterceptor() { return new MappedInterceptor(null, new MyInterceptor()); } 告诉webpack解析test: /\.js?$/,.js文件类型。

.jsx