Ad

Module Build Failed: TypeError: Template Is Not A Function Using Webpack

- 1 answer

I'm try to setup an app environment using webpack and babel, when i run npm start this is the error i get:

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

I already have installed babel and webpack with all the necessary tools (i guess) as you can see here in my 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"
    }
}

This is my env:

n: 2.1.0
npm: 3.5.2
node: v5.2.0 
Ad

Answer

You are trying to use the Babel 6 version of babel-plugin-react-transform but you are still using Babel 5: https://github.com/gaearon/babel-plugin-react-transform/issues/68

Ad
source: stackoverflow.com
Ad