使用browserify,gulp,react.js接收“错误:找不到模块”

凯文德莱昂

所以我一直在玩React.js,gulp和browserify。一切正常,直到我尝试在main.js文件中要求使用模块为止我要求其他文件中的组件/模块没有问题(请参阅下文),但是当我尝试在文件中使用组件/模块main.js时,运行时会收到以下错误消息gulp serve

错误:无法从/ Users / kevin / Documents / MyWork / web / react / node_modules / browserify中的'/ Users / kevin / Documents / MyWork / web / react / app / src / js'找到模块'./components/Feed' /node_modules/resolve/lib/async.js:55:21加载时(/Users/kevin/Documents/MyWork/web/react/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)atx (/Users/kevin/Documents/MyWork/web/react/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)位于/ Users / kevin / Documents / MyWork / web / react / node_modules / browserify / Object.oncomplete上的node_modules / resolve / lib / async.js:22:47(fs.js:107:15)

如果我从中删除require(for Feed.js)语句main.js,则所有内容都会编译并放入适当的dist文件夹中,并且可以正常运行(当然,react.js抱怨缺少模块)。

首先,我的文件夹结构如下所示:

app
│-- gulpfile.js
│-- package.json
└───src
│   │
│   ├───js
│       │-- main.js
│       └───components
│            │-- Feed.js
│            │-- FeedList.js
│            │-- FeedItem.js
│            │-- FeedForm.js
│            │-- ShowAddButton.js
│            └
└───dist

我的gulpfile看起来像这样:

var gulp = require('gulp'),
    connect = require('gulp-connect'),
    open = require("gulp-open"),
    browserify = require('browserify'),
    reactify = require('reactify'),
    source = require("vinyl-source-stream"),
    concat = require('gulp-concat'),
    port = process.env.port || 3031;

// browserify and transform JSX
gulp.task('browserify', function() {
    var b = browserify();
    b.transform(reactify);
    b.add('./app/src/js/main.js');
    return b.bundle()
        .pipe(source('main.js'))
        .pipe(gulp.dest('./app/dist/js'));
});

// launch browser in a port
gulp.task('open', function(){
    var options = {
        url: 'http://localhost:' + port,
    };
    gulp.src('./app/index.html')
    .pipe(open('', options));
});

// live reload server
gulp.task('connect', function() {
    connect.server({
        root: 'app',
        port: port,
        livereload: true
    });
});

// live reload js
gulp.task('js', function () {
    gulp.src('./app/dist/**/*.js')
        .pipe(connect.reload());
});

// live reload html
gulp.task('html', function () {
    gulp.src('./app/*.html')
    .pipe(connect.reload());
});

// watch files for live reload
gulp.task('watch', function() {
    gulp.watch('app/dist/js/*.js', ['js']);
    gulp.watch('app/index.html', ['html']);
    gulp.watch('app/src/js/**/*.js', ['browserify']);
});

gulp.task('default', ['browserify']);

gulp.task('serve', ['browserify', 'connect', 'open', 'watch']);

我的main.js文件如下所示:

var React = require('react'),
    Feed = require('./components/Feed');

React.renderComponent(
    <Feed />,
    document.getElementById('app')
);

Feed.js文件如下所示:

var React = require('react');
var FeedForm = require('./FeedForm');
var ShowAddButton = require('./ShowAddButton');
var FeedForm = require('./FeedForm');
var FeedList = require('./FeedList');

var Feed = React.createClass({

    getInitialState: function() {
        var FEED_ITEMS = [
            { key: '1', title: 'Just something', description: 'Something else', voteCount: 49 },
            { key: '2', title: 'Some more stuff', description: 'Yeah!', voteCount: 34 },
            { key: '3', title: 'Tea is good', description: 'yepp again', voteCount: 15 },
        ];

        return {
            items: FEED_ITEMS
        };
    },

    render: function() {
        return (
            <div>
                <div className="container">
                    <ShowAddButton />
                </div>

                <FeedForm />

                <br />
                <br />

                <FeedList items={this.state.items} />
            </div>
        );
    }

});

module.exports = Feed;

我确定我忽略了一些非常简单的内容...但是我已经呆了几个小时了,似乎无法破解。任何帮助将不胜感激。(显然,我不会为了使内容尽可能简短而发布其他组件的代码,但这并不是问题所在)。

对数神话

您的文件名不是您认为的那样。请注意:

$ find app -type f | awk '{print "_"$0"_"}'
_app/dist/js/main.js_
_app/index.html_
_app/src/js/components/Feed.js _
_app/src/js/components/FeedForm.js _
_app/src/js/components/FeedItem.js_
_app/src/js/components/FeedList.js_
_app/src/js/components/ShowAddButton.js_
_app/src/js/main.js_

您的Feed.js文件实际上是Feed.js<SPACE>相同FeedForm.js重命名它们可以使您的示例存储库构建良好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Gulp错误:找不到模块browserify

来自分类Dev

Gulp与browserify:找不到模块src / js / main.js

来自分类Dev

Gulp错误(找不到模块)

来自分类Dev

Gulp和Babel:错误:找不到模块

来自分类Dev

Gulp和Babel:错误:找不到模块

来自分类Dev

使用Gulp使browserify模块成为外部模块

来自分类Dev

browserify-bundle.js中未捕获的错误“找不到模块”

来自分类Dev

Node.js + browserify-错误:找不到模块“ cls-bluebird”

来自分类Dev

gulp - 使用 browserify 丑化 js 文件?

来自分类Dev

Gulp错误:找不到模块'gulp-watch'

来自分类Dev

Gulp错误:找不到模块'gulp-watch'

来自分类Dev

错误:无法从index.js中解析模块react:在项目中找不到反应

来自分类Dev

Browserify找不到npm模块

来自分类Dev

browserify找不到模块“反应”

来自分类Dev

browserify排除找不到模块

来自分类Dev

发布到Azure时找不到模块gulp.js

来自分类Dev

Typescript + Gulp + Protractor =>找不到模块config.js

来自分类Dev

使用Gulp将browserify模块设置为外部

来自分类Dev

React JS URL错误-“ ./pages/test.js找不到模块:'/ home / Desktop / App / pages中的'https://....../example.json'

来自分类Dev

Gulp测试找不到模块

来自分类Dev

gulp-jshint在使用browserify时发出错误

来自分类Dev

在React中找不到模块'./assets/photo.jpg'错误

来自分类Dev

找不到模块:错误:无法解析“ cypress-react-selector”

来自分类Dev

gulp-webpack错误:找不到输入模块:错误:无法解析模块“ babel”

来自分类Dev

google-trends-api npm找不到使用browserify的模块

来自分类Dev

Gulp Browserify结合JS

来自分类Dev

错误:使用Mocha测试时找不到模块

来自分类Dev

使用karma-webpack时找不到模块错误

来自分类Dev

TypeScript:错误:使用路径时找不到模块

Related 相关文章

  1. 1

    Gulp错误:找不到模块browserify

  2. 2

    Gulp与browserify:找不到模块src / js / main.js

  3. 3

    Gulp错误(找不到模块)

  4. 4

    Gulp和Babel:错误:找不到模块

  5. 5

    Gulp和Babel:错误:找不到模块

  6. 6

    使用Gulp使browserify模块成为外部模块

  7. 7

    browserify-bundle.js中未捕获的错误“找不到模块”

  8. 8

    Node.js + browserify-错误:找不到模块“ cls-bluebird”

  9. 9

    gulp - 使用 browserify 丑化 js 文件?

  10. 10

    Gulp错误:找不到模块'gulp-watch'

  11. 11

    Gulp错误:找不到模块'gulp-watch'

  12. 12

    错误:无法从index.js中解析模块react:在项目中找不到反应

  13. 13

    Browserify找不到npm模块

  14. 14

    browserify找不到模块“反应”

  15. 15

    browserify排除找不到模块

  16. 16

    发布到Azure时找不到模块gulp.js

  17. 17

    Typescript + Gulp + Protractor =>找不到模块config.js

  18. 18

    使用Gulp将browserify模块设置为外部

  19. 19

    React JS URL错误-“ ./pages/test.js找不到模块:'/ home / Desktop / App / pages中的'https://....../example.json'

  20. 20

    Gulp测试找不到模块

  21. 21

    gulp-jshint在使用browserify时发出错误

  22. 22

    在React中找不到模块'./assets/photo.jpg'错误

  23. 23

    找不到模块:错误:无法解析“ cypress-react-selector”

  24. 24

    gulp-webpack错误:找不到输入模块:错误:无法解析模块“ babel”

  25. 25

    google-trends-api npm找不到使用browserify的模块

  26. 26

    Gulp Browserify结合JS

  27. 27

    错误:使用Mocha测试时找不到模块

  28. 28

    使用karma-webpack时找不到模块错误

  29. 29

    TypeScript:错误:使用路径时找不到模块

热门标签

归档