【发布时间】:2018-05-27 13:41:15
【问题描述】:
我的模块.js
function cube(x) {
return x * x * x;
}
const foo = Math.PI + Math.SQRT2;
export { cube, foo };
app.js
import React from 'react';
import ReactDOM from 'react-dom';
import {cube} from './my-module';
console.log(cube(2));
没有错误,但显示,import 似乎不起作用。 stackoverflow,不需要更多细节,代码已经表明了我的意思,请不要强迫我们添加更多细节。
"ReferenceError: cube is not defined
at eval (eval at 35 (http://localhost:8080/build/bundle.js:84:1), <anonymous>:1:1)
at Object.35 (http://localhost:8080/build/bundle.js:84:1)
at __webpack_require__ (http://localhost:8080/build/bundle.js:20:30)
at Object.34 (http://localhost:8080/build/bundle.js:71:18)
at __webpack_require__ (http://localhost:8080/build/bundle.js:20:30)
at http://localhost:8080/build/bundle.js:63:18
at http://localhost:8080/build/bundle.js:66:10"
webpack.config.js
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: /(node_modules)/
},
.babelrc
{
"presets": [
"es2015",
"react",
"stage-0"
],
"plugins": [
"transform-react-jsx"
],
"retainLines": true,
"sourceMaps": "both",
"ignore": [
"*.css"
]
}
【问题讨论】:
-
babelrc不是bablerc -
也是它的
import { cube } from './my-module' -
@azium,嗨,
import React from 'react'行也显示React未定义。 `
标签: javascript webpack babeljs