我尝试使用webpack和babel设置应用程序环境,当我运行npm start
时,这是我得到的错误:
ERROR in ./app/index.js
Module build failed: TypeError: template is not a function
at exports.default (/Users/nerder/Developement/react-test/node_modules/babel-plugin-react-transform/lib/index.js:58:33)
at Function.memoisePluginContainer (/Users/nerder/Developement/react-test/node_modules/babel-core/lib/transformation/file/plugin-manager.js:77:23)
at PluginManager.add (/Users/nerder/Developement/react-test/node_modules/babel-core/lib/transformation/file/plugin-manager.js:209:30)
at File.buildTransformers (/Users/nerder/Developement/react-test/node_modules/babel-core/lib/transformation/file/index.js:237:21)
at new File (/Users/nerder/Developement/react-test/node_modules/babel-core/lib/transformation/file/index.js:139:10)
at Pipeline.transform (/Users/nerder/Developement/react-test/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
at transpile (/Users/nerder/Developement/react-test/node_modules/babel-loader/index.js:12:22)
at Object.module.exports (/Users/nerder/Developement/react-test/node_modules/babel-loader/index.js:71:12)
@ multi main
我已经安装了babel和webpack以及所有必要的工具(我猜),你可以在我的package.json中看到:
{
"name": "react-test",
"version": "1.0.0",
"description": "some test",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"babel": {
"optional": [
"es7.decorators",
"es7.objectRestSpread"
],
"env": {
"start": {
"plugins": [
"react-transform"
],
"extra": {
"react-transform": {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
}
}
}
}
},
"author": "Mister X",
"license": "ISC",
"devDependencies": {
"babel-loader": "^5.4.0",
"babel-plugin-react-transform": "^2.0.0",
"css-loader": "^0.23.1",
"html-webpack-plugin": "^1.7.0",
"react-transform-hmr": "^1.0.1",
"style-loader": "^0.13.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"react": "^0.14.5",
"react-dom": "^0.14.5"
}
}
这是我的环境:
n: 2.1.0
npm: 3.5.2
node: v5.2.0
答案 0 :(得分:2)
您正在尝试使用Babel 6版babel-plugin-react-transform
,但您仍在使用Babel 5:https://github.com/gaearon/babel-plugin-react-transform/issues/68
答案 1 :(得分:0)
在您的应用程序的某个地方,您正在调用一个名为template
的函数,而实际上没有函数可以调用。
如果您正在进行服务器端渲染,那么很可能是您正在编译HTML以进行渲染。也许您正在尝试从underscore编译模板?
var template;
template({someData: 1});