question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`preventAssignment` warning from @rollup/plugin-replace

See original GitHub issue

Current Behavior

I get a warning message from @rollup/plugin-replace when building with tsdx:

@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.

Do not know why I only just started getting this warning message. Any ideas or ways to fix this would be appreciated.

Currently using tsdx in a rush monorepo

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:21
  • Comments:6

github_iconTop GitHub Comments

18reactions
nbgrahamcommented, Mar 3, 2021

I’m definitely not an expert, so not sure if there are negative side effects of this, but I was able to remove the warning by adding a tsdx.config.js file at the root level with

// Not transpiled with TypeScript or Babel, so use plain Es6/Node.js!
const replace = require('@rollup/plugin-replace');

module.exports = {
  // This function will run for each entry/format/env combination
  rollup(config, opts) {
    config.plugins = config.plugins.map(p =>
      p.name === 'replace'
        ? replace({
            'process.env.NODE_ENV': JSON.stringify(opts.env),
            preventAssignment: true,
          })
        : p
    );
    return config; // always return a config.
  },
};

I got 'process.env.NODE_ENV': JSON.stringify(opts.env), from this file.

Maybe there should be a PR to add that option in that file? I’m not sure if there could be breaking changes though. preventAssignment documentation

1reaction
nandorojocommented, Apr 13, 2021

Just to be clear, is the code sample above a good solution, or should I ignore the warning? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: Rollup plugin-replace: preventAssignment set to "false ...
Add preventAssignment: true to your rollup config. It's also not an error, it's a warning, and does not stop you continuing unimpeded. Yeah...
Read more >
@rollup/plugin-replace - npm
@rollup/plugin-replace. TypeScript icon, indicating that this package has built-in type declarations. 5.0.2 • Public • Published 10 days ago.
Read more >
bug: rollup plugin-replace: preventassignment set to false
I get a warning message from @rollup/plugin-replace when building with tsdx: @rollup/plugin-replace: 'preventAssignment' currently defaults to false.
Read more >
Replacing variable with @rollup/plugin-replace throws error
I am trying to inject / replace environment variables with @rollup/plugin-replace. Unfortunately, I get this error:.
Read more >
@rollup/plugin-replace - npm Package Health Analysis | Snyk
Learn more about @rollup/plugin-replace: package health score, ... to Snyk to stay up to date on security alerts and receive automatic fix pull...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found