簡體   English   中英

在ReactJS npm中導入模塊后,將無法編譯

[英]After importing a module in ReactJS npm start wont compile

我正在使用create-react-app使用reddit.js基於reddit API構建一個簡單的庫

我在“ C:.... \\ reddit-gallery”中使用了npm install --save reddit.js

我寫了一些基本代碼,當使用npm start運行它時,我不斷得到:

編譯失敗。

./src/App.js中的錯誤

C:.... \\ reddit的畫廊的\\ src \\ App.js

18:9錯誤'reddit'未定義no-undef

在編碼時,它可以識別該庫,但是在使用npm時,它不能識別該庫中的任何代碼

編碼:

import 'reddit.js';

class App extends Component {

constructor(props){
    super(props);

    this.state = {};

    this.loadSubreddit = this.loadSubreddit.bind(this);
}

loadSubreddit(subre){
    reddit.hot(subre)
        .then(response => {
            return response.json();
        }).then(json => {
            console.log(json)
    })

}

componentWillMount() {
    console.log('comp is mounting');
    this.loadSubreddit('cats');
}

該庫未作為模塊准備,因此您無法導入它。 您只能通過HTML頁面上的<script>標記包括它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM