jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

`preventAssignment` warning from @rollup/plugin-replace #981

Open jessekrubin opened 3 years ago

jessekrubin commented 3 years ago

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

nbgraham commented 3 years ago

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

agilgur5 commented 3 years ago

Thanks for reporting this @jessekrubin and thank you for providing a workaround @nbgraham

Do not know why I only just started getting this warning message.

It's a deprecation warning, so you probably recently upgraded deps or installed TSDX fresh (which would install latest minor+patch of unpinned deps).

I'm not sure if there could be breaking changes though. preventAssignment documentation

Thanks for the link -- no we shouldn't be impacted by this since process.env.NODE_ENV should really never be assigned, only read. It's possible some users may have assigned it, so that warning may be relevant to them (though if it detected actual assignments instead of warning unconditionally, that would be much more useful!)

Maybe there should be a PR to add that option in that file?

PR welcome

nandorojo commented 3 years ago

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

nelsieborja commented 3 years ago

This warning broke my Netlify deployment, have used @nbgraham's code to quickly resolve it.

ehsan-shv commented 2 years ago

I still have the same warning when running npm start and npm run build. Any solution?

lzxb commented 2 years ago

i have the same problem

Kaidanov commented 6 months ago

so frustrating. my tsdx not starting the chrome web with message "@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.

/ Compiling modules...@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.

√ Compiled successfully

Watching for changes" Maybe it's running and I am not finding it on localhost? Like - what port are used by default for tsdx - 3000? 4200? 8080? should it open automatically on yarn start or npm start? It didn't work for me. Tried a workaround of here and still no luck. Frustrating