Webpack 无法解析文件或 dic
Posted
技术标签:
【中文标题】Webpack 无法解析文件或 dic【英文标题】:Webpack cannot resolve file or dic 【发布时间】:2016-09-09 02:49:45 【问题描述】:我的APP:
|--src
||--index.js
||--content.js
|--webpack.config.js
index.js:
const React = require('react');
const ReactDom = require('react-dom');
const View = require('./content');
ReactDom.render(<View/>, document.body);
content.js:
const React = require('react');
class view extends React.Component
render()
return <p> Content </p>
module.exports = View;
webpack.config.js
module.exports =
entry: './src/*',
output:
path: path.join(__dirname, '/build'),
filename: '[name].bundle.js'
,
resolve:
extensions: ['', '.js', '.jsx']
,
module:
loaders: [
test: /\.js|jsx$/,
loader: ['jsx-loader?harmony'],
exclude: /node_modules/
]
,
plugins: [commonsPlugin]
问题:
webpack --display-error-details
哈希:c47fe037926d0dc83af7
版本:webpack 1.13.0
时间:62ms`
Asset Size Chunks Chunk Names
common.js 191 字节 0 [发出] common.js
ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./src/* in /Users/xx/WebstormProjects/jianwenji-react
resolve file
/Users/xx/WebstormProjects/jianwenji-react/src/* doesn't exist
/Users/xx/WebstormProjects/jianwenji-react/src/*.js doesn't exist
/Users/xx/WebstormProjects/jianwenji-react/src/*.jsx doesn't exist
解析目录
/Users/xx/WebstormProjects/jianwenji-react/src/* doesn't exist (directory default file)
/Users/xx/WebstormProjects/jianwenji-react/src/*/package.json doesn't exist (directory description file)
为什么 webpack 找不到那些文件?
【问题讨论】:
【参考方案1】:在这种情况下,entry
应该引用 file 而不是 folder,
module.exports =
entry: './src/index.js'
// ....
注意 - jsx-loader
已弃用,请改用 babel-loader
、babel-preset-react
【讨论】:
以上是关于Webpack 无法解析文件或 dic的主要内容,如果未能解决你的问题,请参考以下文章
Webpack 和 TypeScript 无法解析 Vue 的声明文件
Webpack:移动webpack / react文件的位置后,npm start“找不到模块:错误:无法解析...”