Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacroError with webpack #60

Open
b-d-m-p opened this issue Jan 12, 2021 · 0 comments
Open

MacroError with webpack #60

b-d-m-p opened this issue Jan 12, 2021 · 0 comments

Comments

@b-d-m-p
Copy link

b-d-m-p commented Jan 12, 2021

Getting this error with a project that is using RMWC. I've seen people posting about the same issue with Storybook or Jest. I can't seem to suss out the solution. Any help would be appreciated.

I've also gotten the same error trying the approach with Twin.

 MacroError: The macro you imported from "undefined" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md

I suppressed some potentially related errors about fs and module being undefined with the below in webpack.config.js.

      node: {
            fs: "empty",
             module: "empty"
        },

Here a redacted bit of my ``webpack.config.js`

const path = require("path");
const webpack = require("webpack");
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const htmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Ajv = require("ajv");


...


module.exports = (env, argv) => {
    
    ...

    return {
        mode: mode,
        entry: path.resolve(__dirname, "src/index.tsx"),
        output: {
            filename: "js/[name].js",
            path: path.resolve(__dirname, "dist"),
            publicPath: publicPath
        },
        devtool: isProduction ? false : "source-map",
        devServer: {
            compress: true,
            port: 3001,
            historyApiFallback: true,
            proxy: {
                "/api": {
                    target: "http://localhost:4001",
                    pathRewrite: { "^/api": "" }
                }
            }
        },
        resolve: {
            alias: {
                "@": path.resolve(__dirname, "./src")
            },
            extensions: [".ts", ".tsx", ".js", ".json"]
        },
        plugins: [
            new MiniCssExtractPlugin({
                filename: "css/[name].css",
                sourceMap: true
            }),
              new FaviconsWebpackPlugin({
                logo: './src/logo.png', 
                mode: 'webapp', 
                devMode: 'light', 
                favicons: {
                    appName: 'app',
                    appDescription: 'app description',
                    developerName: 'Me',
                    developerURL: null, 
                    background: '#ffecb3',
                    theme_color: '#FFF',
                    icons: {
                        coast: false,
                        yandex: false
                    }
                }
            }),
            new htmlWebpackPlugin({
                template: path.resolve(__dirname, "src/index.html"),
            })
        ],
        optimization: {
            splitChunks: {
                name: "vendor",
                chunks: "initial"
            }
        },
        performance: {
            maxEntrypointSize: 1000000,
            maxAssetSize: 1000000
        },
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    loader: "ts-loader"
                },
                {
                    enforce: "pre",
                    test: /\.js$/,
                    loader: "source-map-loader",
                    exclude: [
                        // material-ui は source-map を提供してくれていないっぽいので除外
                        /node_modules\/@material/,
                        /node_modules\/@rmwc/
                    ]
                },
                {
                    test: /\.css$/,
                    sideEffects: true,
                    use: [MiniCssExtractPlugin.loader, "css-loader"]
                },
                {
                    test: /\.(?:ico|gif|png|jpg|jpeg|webp|svg)$/i,
                    loader: "file-loader",
                    options: {
                        name: "[path][name].[ext]",
                        context: "src"
                    }
                },
                {
                    test: /\.(woff|woff2|eot|ttf)$/,
                    loader: "file-loader",
                    options: {
                        limit: 8192,
                        name: "[path][name].[ext]",
                        context: "src"
                    }
                }
            ]
        },
        watch
    };
};


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant