dsherret / ts-nameof

nameof in TypeScript
MIT License
492 stars 23 forks source link

ts-nameof does not work with Typescript 4.3 and Webpack #115

Open mhienle opened 3 years ago

mhienle commented 3 years ago

Some relevant dependencies used:

    "@types/ts-nameof": "^4.2.1",
    "ts-loader": "^9.2.3",
    "ts-nameof": "^5.0.0",
    "typescript": "^4.3.2",
    "webpack": "^5.41.1",
    "webpack-cli": "^4.7.2",
    "webpack-dev-server": "^3.11.2",

Relevant parts of webpack-config:

    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: [
                    {
                        loader: 'ts-loader',
                        options: {
                            transpileOnly: true,
                            getCustomTransformers: () => ({ before: [tsNameof] }),
                        },
                    },
                ],
            },
        ],
    },

I get the following error at runtime:

Uncaught ReferenceError: nameof is not defined
    at eval (webpack-internal:///./src/components/Pages/Pages.tsx:36)
    at Object../src/components/Pages/Pages.tsx (bundle.min.app.f52422b76f41c59b99cb.js:15146)
    at __webpack_require__ (bundle.min.app.f52422b76f41c59b99cb.js:23364)
...

As it turns out, the line in bundle.min.app.f52422b76f41c59b99cb.js mentioned in the error contains calls to the function nameof which is indeed not defined anywhere. This seems to happen since Typescript 4.3, at least in my setup: Looking at the minified bundle using the older TS-version 4.2.4, I cannot find such a call, hence everything works fine.

Any help is appreciated! 🙏🏻

RimApp commented 3 years ago

Hi,

I got the same issue "nameof is not defined". "typescript": "^4.3.4", "ts-nameof": "^4.2.2", "@types/ts-nameof": "^4.2.1", "ttypescript": "^1.5.12" Setup mentioned here.

Any solution ?

lixaotec commented 2 years ago

Same situation here