【问题标题】:Module Resolution without Extension无扩展模块分辨率
【发布时间】:2016-08-27 18:07:27
【问题描述】:

鉴于 index.jsx 中的这一行:

import ExampleTable from 'table';

我明白了:

找不到模块:错误:无法解析 global-path-to/application/public/scripts 中的模块“表” @ ./application/public/scripts/index.jsx 19:13-29

但是 table.jsx 位于该文件夹中,我尝试在 webpack.config.js 中定义文件扩展名:

{
entry:SOURCE_DIRECTORY + '/index.jsx',

output:
{
    path:SCRIPT_DIRECTORY,
    filename:'bundle.js'
},

resolve:
{
    extensions:['', '.js', '.jsx']
},    

module:
{
    loaders:
    [
        {
            // Regular expression to find both .js and .jsx files.
            test:/\.jsx?$/,
            include:SCRIPT_DIRECTORY,
            loader: 'babel'
        }
    ]
}
};

$ npm ls --depth 0
├── babel-core@6.7.7
├── babel-loader@6.2.4
├── babel-preset-es2015@6.6.0
├── babel-preset-react@6.5.0
├── jquery@2.2.3
├── jsx-loader@0.13.2
├── material-ui@0.15.0-beta.2
├── react@15.0.1
├── react-dom@15.0.1
├── react-tap-event-plugin@1.0.0
└── webpack@1.13.0

【问题讨论】:

    标签: reactjs ecmascript-6 webpack


    【解决方案1】:

    我认为你只需要使用相对路径,./table,否则它会尝试在 node_modules 中查找 table 包。

    如果你有更复杂的路径,你也可以在 webpack 配置中设置路径解析器:http://webpack.github.io/docs/configuration.html#resolve-root

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多