Skip to content

What is the extent of Vite's CJS-ESM interoperability? #19104

Answered by sapphi-red
silvenon asked this question in Q&A
Discussion options

You must be logged in to vote

For example I noticed that when using ssr.noExternal if a CJS package I installed does the following:

I guess it's because @rollup/plugin-commonjs does not support that case.
That case is difficult to determine whether it runs always:

module.exports = {
  foo: foo && require('./foo'), // this is conditional require
  bar: foo ? require('./foo') : false, // this is conditional require
}

const throw = () => { throw '' }
module.exports = {
  foo: (throw(), require('./foo')), // this is conditional require
}

any usage of __dirname and __filename will remain as-is, they won't get converted to import.meta.dirname and import.meta.filename.

Linking my comment here for reference: #19036 (comm…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by silvenon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants