TypeError: main.startsWith is not a function
badver opened this issue ยท 20 comments
Got this error today:
rn-nodeify --install buffer,process,console,stream,vm,events,path --hack
not overwriting "buffer"
not overwriting "process"
not overwriting "console-browserify"
not overwriting "stream-browserify"
not overwriting "vm-browserify"
not overwriting "events"
not overwriting "path-browserify"
not overwriting "readable-stream"
not overwriting shim.js. For the latest version, see rn-nodeify/shim.js
removing browser exclude node_modules/htmlparser2/package.json readable-stream
normalized "main" browser mapping in immediate, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in lie, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in pouchdb-find, fixed here: https://github.com/facebook/metro-bundler/pull/3
removing browser exclude node_modules/tweetnacl/package.json buffer
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
removing browser exclude node_modules/sqlite3/node_modules/tweetnacl/package.json buffer
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
/usr/local/lib/node_modules/rn-nodeify/cmd.js:327
const alt = main.startsWith('./') ? main.slice(2) : './' + main
^
TypeError: main.startsWith is not a function
at /usr/local/lib/node_modules/rn-nodeify/cmd.js:327:24
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
Any suggestions?
I had the same issue since today. It was caused by package browserify/resolve, which introduced invalid package.json in its tests:
"main": [
"why is this a thing",
"srsly omg wtf"
]
This package.json is parsed by rn-nodeify and results in this error. As a workaround you may force version 1.8.1 of resolve
in package.json of your project.
same problem here. @mboguc how force resolve version?
@mboguc great find, could you please provide your solution?
I am not sure which is the dependency from rn-nodeify
that is using the resolve
browserify package.
@shardick @Vanclief put it in dependencies in your package.json
, but be sure to point to exact version ("compatible" may allow 1.9.0).
Looking through package-lock.json
, it would seem that resolve
is required by @babel/core
which in turn is required by metro
, React Native packager.
Thank you @mboguc !
I put "resolve": "1.8.1" in my main package.json and the problem was solved.
I've added a check if main isn't a string for such cases.
same issue... after added "resolve" in the package
@nyl9488 maybe you put it in a wrong place.
It should be in the dependencies section and with "1.8.1" exactly.
And check what version in your package-lock.json. If you'll see 1.9.0 - that's bad.
Try reinstall with: npm install --save resolve@1.8.1
Also, there's already a fix for this issue, I hope @mvayngrib will publish this package soon so we can use it without forcing version.
resolved after remove node_modules
Could not fix this issue until updated dependency:
- "rn-nodeify": "github:mvayngrib/rn-nodeify"
+ "rn-nodeify": "github:tradle/rn-nodeify"
@badver's fix was published in 10.0.1, so everyone should be able to install the latest from npm
Same error with version 10.0.1
rn-nodeify --install stream,process,util --hack
not overwriting "stream-browserify"
not overwriting "process"
not overwriting "readable-stream"
not reinstalling util
not overwriting shim.js. For the latest version, see rn-nodeify/shim.js
failed to parse node_modules/resolve/test/resolver/baz/package.json
failed to parse node_modules/resolve/test/resolver/dot_main/package.json
failed to parse node_modules/resolve/test/resolver/browser_field/package.json
failed to parse node_modules/resolve/test/resolver/dot_slash_main/package.json
/usr/local/lib/node_modules/rn-nodeify/cmd.js:327
const alt = main.startsWith('./') ? main.slice(2) : './' + main
^
TypeError: main.startsWith is not a function
at /usr/local/lib/node_modules/rn-nodeify/cmd.js:327:24
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:532:3)
Forcing resolve to version 1.8.1 failed as well.
react-native:0.59.2
@njacot are you sure you use version 10.0.1 ? There is no way, if "main" isn't a string, to execute that line of code.
yes, here is my package.json devDependencies section:
"devDependencies": {
"@babel/core": "7.4.0",
"@babel/runtime": "7.4.2",
"@react-native-community/eslint-config": "0.0.3",
"babel-jest": "24.5.0",
"eslint": "5.15.3",
"jest": "24.5.0",
"metro-react-native-babel-preset": "0.53.1",
"react-test-renderer": "16.8.3",
"rn-nodeify": "^10.0.1"
},
I am trying to install the https://github.com/PeelTechnologies/react-native-tcp that is why I need rn-nodeify. Any idea where else could be the issue?
@njacot just in case, can you check the "version" field in node_modules/rn-nodeify/package.json
and confirm it's 10.0.1?
@mvayngrib Yes the version field is like so: "version": "10.0.1",
@njacot maybe you have rn-nodeify
installed globally? Try using ./node_modules/.bin/rn-nodeify
instead
@mvayngrib I had indeed a global version 10.0.0. I didn't think about a global installation. Everything works now. Thank you so much!
I'd recommend update to latest rn-nodeify as a fix :D. And adding the resolve: 1.8.1 block to resolutions on package.json