External Library using Rollup.JS with Formik doesn't respect named exports External Library using Rollup.JS with Formik doesn't respect named exports reactjs reactjs

External Library using Rollup.JS with Formik doesn't respect named exports


You are probably thinking no one on planet earth will ever have the same obscure error. You would be wrong. Found the solution. (It was related to order on the plugins)

plugins: [    globals(),    builtins(),    externals(),    babel({ exclude: 'node_modules/**', presets: ['@babel/env', '@babel/preset-react'] }),    commonjs({      namedExports: {        // left-hand side can be an absolute path, a path        // relative to the current directory, or the name        // of a module in node_modules        'node_modules/formik/node_modules/scheduler/index.js' : ['unstable_runWithPriority'],      }    }),    peerDepsExternal(),    postcss({ extract: true, plugins: [autoprefixer] }),    json({  include: 'node_modules/**' }),    localResolve(),    resolve({dedupe: [ 'react', 'react-dom' ]}),    filesize()  ]


this order of plugins worked for me to solve the issue.

plugins: [    babel({      exclude: 'node_modules/**',      presets: ['@babel/env', '@babel/preset-react'],    }),    typescript({ useTsconfigDeclarationDir: true }),    commonjs({      namedExports: {        // left-hand side can be an absolute path, a path        // relative to the current directory, or the name        // of a module in node_modules        'node_modules/formik/node_modules/scheduler/index.js': [          'unstable_runWithPriority',        ],      },    }),    peerDepsExternal(),    scss(),    json({      compact: true,    }),    resolve(),  ],


Use this syntax:

      namedExports: {        'scheduler': ['unstable_runWithPriority', 'unstable_LowPriority']      }