npm build with Browserify - Error: Cannot find module
npm build with Browserify - Error: Cannot find module
当 运行 npm 构建时:
"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'
编辑:
我发现它只有在我提供组件的完整路径时才有效,这很奇怪。任何人都知道什么可能导致这个问题?可能是一些环境变量或 ?
在导入路径的开头使用 ./
:
import { MainInput } from './components/maininput.jsx'
当 运行 npm 构建时:
"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'
编辑: 我发现它只有在我提供组件的完整路径时才有效,这很奇怪。任何人都知道什么可能导致这个问题?可能是一些环境变量或 ?
在导入路径的开头使用 ./
:
import { MainInput } from './components/maininput.jsx'