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

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

Open
mhienle opened this issue Jul 2, 2021 · 2 comments
Open

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

mhienle opened this issue Jul 2, 2021 · 2 comments

Comments

@mhienle
Copy link

mhienle commented Jul 2, 2021

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
Copy link

RimApp commented Sep 12, 2021

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
Copy link

Same situation here

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

3 participants