我试图在linux上使用sudo npm run build
构建项目,但它给了我这个错误:
ubuntu@ip:/var/www/reactcamera$ sudo npm run build
> youtubechannelvideos@0.1.0 build /var/www/reactcamera
> react-scripts build
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve 'react-qr-reader' in '/var/www/reactcamera/src'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! youtubechannelvideos@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the youtubechannelvideos@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2018-02-23T19_07_23_567Z-debug.log
的package.json
{
"name": "youtubechannelvideos",
"version": "0.1.0",
"private": true,
"dependencies": {
"fetch": "^1.1.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.1",
"react-youtube": "^7.5.0",
"dns": "file:./src/mock/dns",
"react-qr-code": "0.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import YouTube from 'react-youtube';
import Fetch from 'fetch';
import QrReader from 'react-qr-reader';
class Test2 extends React.Component{
constructor(props){
super(props)
}
render(){
return (<RenderOnClick buttonName="Show Camera" element={<ShowPreview/>}/>);
}
}
ReactDOM.render(<Test2/>, document.getElementById("root"));
答案 0 :(得分:0)
Module not found: Error: Can't resolve 'react-qr-reader'
...
import QrReader from 'react-qr-reader';
运行npm install --save react-qr-reader
或yarn add react-qr-reader
您有react-qr-code
,但没有react-qr-reader
答案 1 :(得分:0)
首先应运行npm install
以确保在构建之前安装所有依赖项。