【问题标题】:npm build with Browserify - Error: Cannot find module使用 Browserify 构建 npm - 错误:找不到模块
【发布时间】:2017-01-20 01:25:21
【问题描述】:

运行 npm build 时:

"build": "browserify -t [ babelify --presets [ es2015 react ] ] app/assets/app.jsx -o public/javascripts/app.js"

我收到以下错误:

Error: Cannot find module 'components/maininput.jsx' from 'C:\Users\Work\Documents\NetBeansProjects\Project\app\assets'

项目结构如下:

app
|
└────assets
    │   app.jsx
    |
    └───components 
           maininput.jsx

在 app.jsx 中的导入看起来像这样:

import React from 'react';
import ReactDOM from 'react-dom';
import { MainInput } from '../components/maininput.jsx'

maininput.jsx 中的导出如下所示:

export default class MainInput extends React.Component {
  //some code and render()
}

我还创建了 GulpFile,也出现了同样的错误:

{ Error: Cannot find module '../components/maininput.jsx'

编辑: 我发现它只有在我提供组件的完整路径时才有效,这很奇怪。任何人都知道什么可能导致这个问题?可能是一些环境变量或?

【问题讨论】:

    标签: javascript reactjs npm browserify


    【解决方案1】:

    在导入路径的开头使用./

    import { MainInput } from './components/maininput.jsx'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-06
      • 2014-08-17
      • 1970-01-01
      • 2016-06-14
      • 2015-10-31
      • 2019-05-22
      • 1970-01-01
      • 2020-01-30
      相关资源
      最近更新 更多