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

[Bug]: You gave us a visitor for the node type TSInstantiationExpression but it's not a valid type #14587

Closed
1 task done
ngregory-rbi opened this issue May 25, 2022 · 17 comments
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@ngregory-rbi
Copy link

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

N/A. This is run through Metro Bundler (the bundler for React Native).

Configuration file name

babel.config.js

Configuration

Note: this is a compiled config.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const configFunc = (api) => {
    api.cache.forever();
    return {
        presets: ['babel-preset-expo'],
    };
};
exports.default = configFunc;

Current and expected behavior

The Metro bundler successfully bundles my app.

Environment

N/A

Possible solution

Look at what is missing in the implementation of #14322 .

Additional context

This change seems to be related to Babe v7.18.0 (or thereabouts).

Here is a StackOverflow question having this issue: https://stackoverflow.com/questions/72328356/

And here are some other GitHub issues in some other projects:
vercel/next.js#37080
umijs/dumi#1093

It appears #14322 was not implemented properly.

Due to the complicated nature of my app, it appears it will difficult to simply revert my Babel version, as it is required upstream with many different versions. A fix is urgently needed.

@babel-bot
Copy link
Collaborator

Hey @ngregory-rbi! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

Do you have a complete stack trace?

As a workaround, delete @babel/types from your lockfile and update it.

@ngregory-rbi
Copy link
Author

Do you have a complete stack trace?

As a workaround, delete @babel/types from your lockfile and update it.

I don't, but if I recall it originated in my main file, so not much of a stack to speak of. And this issue started happening after removing node_modules and running yarn install, so I don't think there would be a lockfile issue, but I can try that.

@nicolo-ribaudo
Copy link
Member

Also, it would help if you can share the versions of the various Babel packages present in your lockfile.

@ngregory-rbi
Copy link
Author

I just deleted both node_modules and my yarn.lock file and ran yarn again. It appears this may resolve it. I'll update you in a few minutes.

@ngregory-rbi
Copy link
Author

I just deleted both node_modules and my yarn.lock file and ran yarn again. It appears this may resolve it. I'll update you in a few minutes.

Ok this did resolve the issue. It appears you were correct that my @babel/types was not updated correctly. I'm not sure why though, although that may just be an issue with Yarn's module resolution system.

@nicolo-ribaudo
Copy link
Member

I'm glad that it works now!

@cateiru
Copy link

cateiru commented May 27, 2022

Hello, @nicolo-ribaudo

I too encountered the same error when building.

I suspect the problem is that the latest version of @babel/preset-typescript is 7.17.12, not 7.18.X.

Here are the branches we used for verification

https://github.com/cateiru/babel-preset-ts-error

yarn create next-app --typescript .
yarn add --dev jest
yarn add --dev babel-jest @babel/core @babel/preset-env
yarn add --dev @babel/preset-typescript
touch babel.config.js

vi babel.config.js // edit: https://jestjs.io/docs/getting-started#using-typescript
~/r/babel-preset-ts-error » yarn build                                                                           main ✗
yarn run v1.22.18
$ next build
info  - Checking validity of types
info  - Disabled SWC as replacement for Babel because of custom Babel configuration "babel.config.js" https://nextjs.org/docs/messages/swc-disabled
info  - Using external babel configuration from /home/user/repositories/babel-preset-ts-error/babel.config.js
info  - Creating an optimized production build
Failed to compile.

./pages/_app.tsx
Error: [BABEL] /home/user/repositories/babel-preset-ts-error/pages/_app.tsx: You gave us a visitor for the node type TSInstantiationExpression but it's not a valid type
    at verify (/home/name/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1890:372053)
    at Function.explode (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1890:370915)
    at /home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2774429
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2804218)
    at Generator.next (<anonymous>)
    at evaluateSync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2727582)
    at Function.sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2725598)
    at sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2804714)
    at sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2726915)

./pages/index.tsx
Error: [BABEL] /home/user/repositories/babel-preset-ts-error/pages/index.tsx: You gave us a visitor for the node type TSInstantiationExpression but it's not a valid type
    at verify (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1890:372053)
    at Function.explode (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1890:370915)
    at /home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2774429
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2804218)
    at Generator.next (<anonymous>)
    at evaluateSync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2727582)
    at Function.sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2725598)
    at sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2804714)
    at sync (/home/user/repositories/babel-preset-ts-error/node_modules/next/dist/compiled/babel/bundle.js:1:2726915)


> Build failed because of webpack errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@nicolo-ribaudo
Copy link
Member

Thanks for the reproduction! The lockfile versions look correct, so this is indeed a bug. I'll try to work on a fix later today!

@nicolo-ribaudo
Copy link
Member

What I have found so far: even if your lockfile says @babel/types@7.18.2, Next.js is still running Babel with an older @babel/types version that they bundle.

(However, everything should work with the old version. I'm still investigating).

@camello222
Copy link

Sorry, what is the workaround?
I get this issue when trying to initialize a new expo project with the typescript template, and removing the yarn.lock and the node_modules and then re-running the yarn install don't fix the issue for me.

@nicolo-ribaudo
Copy link
Member

So far the only workaround is to make sure that you are using a 7.17.x version of @babel/plugin-transform-typescript.

@camello222
Copy link

Thanks, Nicolo. By forcing use of @babel/core and @babel/plugin-transfor-typescript to version '7.17.12' and re-creating my dependencies, I don't have this problem anymore!

@nicolo-ribaudo
Copy link
Member

We released 7.18.4 of the TS plugin which should properly fix this. Could you check if it works? 🙏

@camello222
Copy link

camello222 commented Jun 1, 2022

I chaged the version of the plugin-transfor-typescript package to 7.18.4 and it works fine, but previously I wasn't specifying this package in my dependencies explicitly. Babel/core still using 7.17.12. I guess you will need to port the fix there.

@nicolo-ribaudo
Copy link
Member

You can probably now remove it from your dependencies, the only problem is that your lockfile contained an older version of the plugin.

@cateiru
Copy link

cateiru commented Jun 1, 2022

Hi! @nicolo-ribaudo

Sorry for the delay in replying.
I was able to confirm that it builds correctly.

Thank you for your quick response 🙇

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants