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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: unable to use addExternalDependency #14252

Closed
1 task
goatandsheep opened this issue Feb 8, 2022 · 3 comments
Closed
1 task

[Bug]: unable to use addExternalDependency #14252

goatandsheep opened this issue Feb 8, 2022 · 3 comments
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@goatandsheep
Copy link

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

Code is here: https://github.com/goatandsheep/react-native-dotenv/blob/64cfaec582900712eac53d3f3cdf1c079ecc7c61/index.js

it's based on the following sample code:

function plugin(api) {
  const dotEnvFilename = `${process.cwd()}/.env`;

  const env = api.cache.using(() => fs.readFileSync(dotEnvFilename, "utf8"));
  api.addExternalDependency(dotEnvFilename);
  
  return {
    visitor: {}...
  }
}

Configuration file name

.babelrc

Configuration

No response

Current and expected behavior

Currently the following errors:

  • the cache function gets "Cannot change caching after evaluation has completed"
  • and the addExternalDependency function gets "Cannot add property 0, object is not extensible"

Expecting no errors

Environment

  • Babel Version : v7.17.2
  • Node: v14.17.5
  • Yarn: 1.22.15

Possible solution

No response

Additional context

I'm testing out the addExternalDependency function for the new version v7.17.2 and the function is present in my library but I'm getting some errors. Babel has worked previously and it works when I do not have the new function so my guess is my usage of the function is incorrect.

@babel-bot
Copy link
Collaborator

Hey @goatandsheep! 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

Caching must be configured in the plugin factory (before line 23 on your code), since it tells Babel when it needs to reinstantiate your plugin.

I see you need to access the options in order to configure the cache: you can get them from the second factory parameter, after api.

@goatandsheep
Copy link
Author

Thank you! This helped goatandsheep/react-native-dotenv#288

@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 May 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question 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

3 participants