Lee.zm
Lee.zm

Reputation: 105

Webpack cannot resolve file or dic

MyAPP:

|--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]
}

Problems:

webpack --display-error-details

Hash: c47fe037926d0dc83af7

Version: webpack 1.13.0

Time: 62ms`

Asset       Size  Chunks             Chunk Names

common.js 191 bytes 0 [emitted] 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 resolve directory /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)

Why webpack can't find that files?

Upvotes: 2

Views: 310

Answers (1)

Oleksandr T.
Oleksandr T.

Reputation: 77502

In this case entry should refer to file not to folder,

module.exports = {
  entry: './src/index.js'
  // ....
}

Note - jsx-loader is deprecated, use babel-loader, babel-preset-react instead

Upvotes: 2

Related Questions