JS的新手,并试图用React.js编写一个简单的反应式引导程序。我在使用API库时遇到问题,似乎无法导入它。
使用webpack进行测试编译时出现以下错误:
ERROR in ./~/steem/lib/api/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./methods in /home/james/Desktop/React-MessageBoard-master/node_modules/steem/lib/api
@ ./~/steem/lib/api/index.js 33:15-35
ERROR in ./~/steem/config.json
Module parse failed: /home/james/Desktop/React-MessageBoard-master/node_modules/steem/config.json Unexpected token (2:13)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:13)
我通过npm成功安装了API库,现在可以在node_modules
中找到。
然后,我使用import命令通过index.js导入我的库。
在我的index.js下面:
import 'core-js/fn/object/assign';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/Main';
import steem from 'steem'
// Render the main component into the dom
ReactDOM.render(<App />, document.getElementById('app'));
和webpack.config.js:
'use strict';
const path = require('path');
const args = require('minimist')(process.argv.slice(2));
// List of allowed environments
const allowedEnvs = ['dev', 'dist', 'test'];
// Set the correct environment
let env;
if (args._.length > 0 && args._.indexOf('start') !== -1) {
env = 'test';
} else if (args.env) {
env = args.env;
} else {
env = 'dev';
}
process.env.REACT_WEBPACK_ENV = env;
/**
* Build the webpack configuration
* @param {String} wantedEnv The wanted environment
* @return {Object} Webpack config
*/
function buildConfig(wantedEnv) {
let isValid = wantedEnv && wantedEnv.length > 0 && allowedEnvs.indexOf(wantedEnv) !== -1;
let validEnv = isValid ? wantedEnv : 'dev';
let config = require(path.join(__dirname, 'cfg/' + validEnv));
return config;
}
module.exports = buildConfig(env);
编辑:API库中有一个methods.json,可在此处找到:
/home/james/Desktop/React-MessageBoard-master/node_modules/steem/lib/api
我认为这可能是根本原因...... 欢迎任何帮助!