Open rahul-mahato11 opened 1 month ago
hey @rahul-mahato11, please try with include: [/node_modules/]
so that everything get's transpiled
This doesn't works as it then tries to transpile a library nanoid/non-secure
which is included in some other library, and then it throws this
nanoid/non-secure/index.cjs
let urlAlphabet =
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
let customAlphabet = (alphabet, defaultSize = 21) => {
return (size = defaultSize) => {
let id = ''
let i = size
while (i--) {
id += alphabet[(Math.random() * alphabet.length) | 0]
}
return id
}
}
let nanoid = (size = 21) => {
let id = ''
let i = size
while (i--) {
id += urlAlphabet[(Math.random() * 64) | 0]
}
return id
}
module.exports = { nanoid, customAlphabet }
is this on v4 of Re.Pack?
Yes v4.1.1
hmm you can try aliasing nanoid/non-secure
to point to the entry for react-native which is index.browser.js
, let me know if that works - without a full picture I'm only limited to guesswork like this 🤷
Hi @rahul-mahato11,
please try adding type: 'javascript/dynamic'
as well, like this:
{
test: /\.[cm]?[tj]sx?$/,
include: [/node_modules/],
use: 'babel-loader',
type: 'javascript/dynamic'
}
Adding type: 'javascript/dynamic'
throws a new error while bundling
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
100%
UnsupportedFeatureWarning: Cannot statically analyse 'require(…, …)' in line 6
at AMDRequireDependenciesBlockParserPlugin.processCallRequire (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js:326:8)
at Hook.eval [as call] (eval at create (/Users/rahulmahato/Documents/app-repack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
at JavascriptParser.callHooksForInfoWithFallback (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3789:24)
at JavascriptParser.callHooksForInfo (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3738:15)
at JavascriptParser.walkCallExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3511:26)
at JavascriptParser.walkExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2924:10)
at JavascriptParser.walkTerminatingStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2096:32)
at JavascriptParser.walkReturnStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2103:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1949:10)
at JavascriptParser.walkNestedStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1982:8)
at JavascriptParser.walkIfStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2030:9)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1943:10)
at JavascriptParser.walkStatements (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1809:9)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2002:9
at JavascriptParser.inBlockScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3924:3)
at JavascriptParser.walkBlockStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1997:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1913:10)
at JavascriptParser.walkNestedStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1982:8)
at JavascriptParser.walkIfStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2030:9)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1943:10)
at JavascriptParser.walkStatements (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1809:9)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2002:9
at JavascriptParser.inBlockScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3924:3)
at JavascriptParser.walkBlockStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1997:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1913:10)
at JavascriptParser.walkNestedStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1982:8)
at JavascriptParser.walkIfStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2030:9)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1943:10)
at JavascriptParser.walkStatements (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1809:9)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2002:9
at JavascriptParser.inBlockScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3924:3)
at JavascriptParser.walkBlockStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1997:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1913:10)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2309:10
at JavascriptParser.inFunctionScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3903:3)
at JavascriptParser.walkFunctionDeclaration (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2300:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1940:10)
at JavascriptParser.walkStatements (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1809:9)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2002:9
at JavascriptParser.inBlockScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3924:3)
at JavascriptParser.walkBlockStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1997:8)
at JavascriptParser.walkStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:1913:10)
at /Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3420:10
at JavascriptParser.inFunctionScope (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3903:3)
at JavascriptParser._walkIIFE (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3405:8)
at JavascriptParser.walkCallExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3471:9)
at JavascriptParser.walkExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2924:10)
at JavascriptParser.walkCallExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:3526:11)
at JavascriptParser.walkExpression (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2924:10)
at JavascriptParser.walkTerminatingStatement (/Users/rahulmahato/Documents/app-repack/node_modules/webpack/lib/javascript/JavascriptParser.js:2096:32)
error Command failed with exit code 2.
are you using require
with 2 params somewhere in your code? or passing array to require? Perhaps some other dependency in your config has something like this and it's getting picked up, hard to tell
You can try using type: 'javascript/dynamic'
on the specified node_modules as before
whats the benfit of type: 'javascript/dynamic'
?
it labels the module as CJS - since the RN babel preset has a rule to transform everything to CJS it makes sense in this scenario - there are cases where a module might be marked as ESM but it will get transpiled to CJS and errors like exports
is not defined might occur.
Environment
Metro to Repack migration
Description
I am trying to migrate from metro to re-pack to get bundle splitting benefits, I am able to setup the dev environment but somehow the release bundle breaks when opening a screen under react-navigation, If I just remove the navigation wrapper and return a View directly it works fine.
Reproducible Demo
here's my package.json dependencies
webpack.config.js