I have a preact app which is using rollup + buble. I need to use another component text-mask which uses React. I am trying to create alias within my rollup build file. For the client side, it works flawlessly however when building on the server side, it fails. My plugin section within my rollup build config is as below :-
plugins: [
alias({
'react': path.resolve('./node_modules/preact-compat/dist/preact-compat.es.js'),
'react-dom': path.resolve('./node_modules/preact-compat/dist/preact-compat.es.js')
}),
nodeResolve({ jsnext: true, browser: true }),
commonjs({ include: ['node_modules/**'], namedExports: { 'preact-redux': ['connect', 'Provider'] } }),
replace({ '__CLIENT__': true, 'process.env.NODE_ENV': JSON.stringify('production') }),
images,
buble({ jsx: 'h', objectAssign: 'Object.assign' }),
!isDev && uglify(uglifyConfig) // uglify slows builds
]
I came across an issue where it says there are issues while using preact-compat on a server side app and it was suggesting to use module-alias as an alternative. So i tried giving the below module-alias in my node server file :-
require('module-alias').addAliases({
'react': 'preact-compat',
'react-dom': 'preact-compat'
})
Even after doing that, i still get the below error :-
Error: Cannot find module 'react'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at r (/my-app/node_modules/react-text-mask/dist/reactTextMask.js:1:145)
at Object.<anonymous> (/my-app/node_modules/react-text-mask/dist/reactTextMask.js: 1:315)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)