Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError [ERR_OUT_OF_RANGE] #65

Closed
gildebrand opened this issue Jul 9, 2019 · 24 comments · Fixed by #381
Closed

RangeError [ERR_OUT_OF_RANGE] #65

gildebrand opened this issue Jul 9, 2019 · 24 comments · Fixed by #381

Comments

@gildebrand
Copy link

Version:
native-run: 0.2.7
node: 10.16.0

Description:
Native-run fails when running both through ionic run ios and when running native-run directly. I've tried running ionic run ios both with and without the --l flag with same result. Tried running native-run ios --app "platforms/ios/build/device/App Admin.ipa" --device --connect --forward 8100:8100 with same result.

Command Output:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 37. Received 38
    at boundsError (internal/buffer.js:49:9)
    at writeU_Int8 (internal/buffer.js:558:5)
    at Buffer.writeUInt8 (internal/buffer.js:565:10)
    at toCString (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
    at AFCClient.makeDirectory (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:84:19)
    at AFCClient.uploadDirectory (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:89:20)
    at uploadApp (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/dist/ios/utils/device.js:85:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Environment Info:

Ionic:

   Ionic CLI                     : 5.2.1 (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.5.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 8 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.7

System:

   Android SDK Tools : 26.1.1 (/Users/antongildebrand/Library/android-sdk-macosx)
   ios-deploy        : 1.9.4
   ios-sim           : 8.0.1
   NodeJS            : v10.16.0 (/Users/antongildebrand/.nvm/versions/node/v10.16.0/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001

macOS version:
10.14.5

Xcode version:
10.2.1

@gildebrand gildebrand added the ios label Jul 9, 2019
@imhoffd
Copy link
Contributor

imhoffd commented Jul 9, 2019

@gildebrand Can you run native-run ios --app "platforms/ios/build/device/App Admin.ipa" --device --connect --forward 8100:8100 --verbose and post the output? (notice the --verbose flag.) If it's too large, the last few dozen lines will probably be enough. Thanks!

@DanielTizon
Copy link

I'm getting the same error. My output:

client:afc closeFile fd: 185,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 186,0,0,0,0,0,0,0 +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1035,"operation":14} +2ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1036,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1037,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1038,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1039,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  client:afc writeFile: 187,0,0,0,0,0,0,0 +1ms
  client:afc writeFile: 188,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 189,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 190,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 191,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 187,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 188,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 189,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 190,0,0,0,0,0,0,0 +1ms
  client:afc closeFile fd: 191,0,0,0,0,0,0,0 +0ms
  native-run Caught fatal error: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 59. Received 60
  native-run     at boundsError (internal/buffer.js:49:9)
  native-run     at writeU_Int8 (internal/buffer.js:558:5)
  native-run     at Buffer.writeUInt8 (internal/buffer.js:565:10)
  native-run     at toCString (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
  native-run     at AFCClient.openFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:50:9)
  native-run     at AFCClient.uploadFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:69:24) +0ms
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 59. Received 60
    at boundsError (internal/buffer.js:49:9)
    at writeU_Int8 (internal/buffer.js:558:5)
    at Buffer.writeUInt8 (internal/buffer.js:565:10)
    at toCString (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
    at AFCClient.openFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:50:9)
    at AFCClient.uploadFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:69:24)
  client:afc openFile: PublicStaging/Moments.app/www/assets/pruebas.mp3 +83ms

@symeonmattes
Copy link

I have the same error. Any solutions?

@kanchana123
Copy link

Hey, I had a similar error. For me it was because the app name in config.xml had problems. I fixed the name and then saved cordova plugins. Removed platform iOS and added it back. Then app built successfully. Hope this helps.

@pipoa
Copy link

pipoa commented Sep 2, 2019

Never Ever success with native-run

$ ionic cordova run ios   hangs/stucks forever....  
$ native-run ios --app "platforms/ios/build/device/myapp.ipa" 
Caught fatal error: RangeError [ERR_OUT_OF_RANGE]: The value of "offset"
 is out of range. It must be >= 0 and <= 55. Received 56

Instead, cordova, --no-native-run is running very well
native-run --version 0.2.8

@coloz
Copy link

coloz commented Jan 18, 2020

same error

@cxcxcxcx
Copy link

Same problem. This seems related to non-latin chars in the path. Note that the app name is not displayed correctly.

client:afc makeDirectory: PublicStaging/读典籍.app +0ms
native-run Caught fatal error: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 27. Received 28
native-run at boundsError (internal/buffer.js:77:9)
native-run at writeU_Int8 (internal/buffer.js:732:5)
native-run at Buffer.writeUInt8 (internal/buffer.js:739:10)
native-run at toCString (/Users/chenxing/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
native-run at AFCClient.makeDirectory (/Users/chenxing/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:84:19)
native-run at AFCClient.uploadDirectory (/Users/chenxing/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:89:20)
native-run at uploadApp (/Users/chenxing/node_modules/native-run/dist/ios/utils/device.js:84:21)
native-run at processTicksAndRejections (internal/process/task_queues.js:97:5)
native-run at async Object.runOnDevice (/Users/chenxing/node_modules/native-run/dist/ios/utils/device.js:31:9)
native-run at async Object.run (/Users/chenxing/node_modules/native-run/dist/ios/run.js:52:13) {
native-run code: 'ERR_OUT_OF_RANGE'
native-run } +0ms

@cxcxcxcx
Copy link

Sigh, turns out that it's in https://www.npmjs.com/package/node-ioslib , which is not open sourced.

In the generated afs.js, it's clear that var buf = Buffer.alloc(s.length + 1); should be replaced by var buf = Buffer.alloc(Buffer.byteLength(s) + 1);

Also, all the strings responded should be decoded with UTF-8, rather than String.fromCharCode(token)

@alexandertrev
Copy link

Any news on the issue?

@imhoffd
Copy link
Contributor

imhoffd commented May 26, 2020

@cxcxcxcx (and others) I've created a PR that open sources node-ioslib: #124 When it's merged, would you be up for creating a PR to implement the proposed fixes?

@Florian-crg
Copy link

Florian-crg commented Sep 14, 2020

I got a similar error when I run "ionic cordova run ios -l --external --device"
All works good if I run it from xCode or the browser though.

The output :

> native-run ios --app platforms/ios/build/device/Preprod.ipa --device --forward 8100:8100
[native-run] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 85. Received 86
[native-run]     at boundsError (internal/buffer.js:77:9)
[native-run]     at writeU_Int8 (internal/buffer.js:732:5)
[native-run]     at Buffer.writeUInt8 (internal/buffer.js:739:10)
[native-run]     at toCString (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
[native-run]     at AFCClient.openFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:50:9)
[native-run]     at AFCClient.uploadFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:69:24)
[ERROR] An error occurred while running subprocess native-run.

@rgustavsson
Copy link

rgustavsson commented Sep 17, 2020

Any workarounds? I have a repository where the command is working, and a repository where I get this error. Its on the same development machine..

UPDATE: Found that no-native-run worked well so that's an OK workaround

@imhoffd imhoffd added this to Backlog 🤖 in Capacitor Engineering ⚡️ via automation Dec 7, 2020
@imhoffd imhoffd added the bug label Dec 7, 2020
@ToschaA
Copy link

ToschaA commented Jul 9, 2022

I have the same problem, none of the above work for a fix for Capacitor. For me it happend after I deleted the android platform and tried to run on my iOS (iPhone), although it works perfectly when running from xCode or browser.

Has anyone found the cause and a solution for this problem for apps running capacitor?

@muhammad-gul-dm
Copy link

I got the same error. Please help!

[error] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 74. Received 75
[capacitor] at new NodeError (node:internal/errors:371:5)
[capacitor] at boundsError (node:internal/buffer:86:9)
[capacitor] at writeU_Int8 (node:internal/buffer:741:5)
[capacitor] at Buffer.writeUInt8 (node:internal/buffer:748:10)
[capacitor] at toCString (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:162:9)
[capacitor] at AFCClient.openFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:52:9)
[capacitor] at AFCClient.uploadFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:74:24)
[capacitor] node:events:368
[capacitor] throw er; // Unhandled 'error' event

@chungmarcoo
Copy link

I got the same error. Please help!

[error] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 74. Received 75 [capacitor] at new NodeError (node:internal/errors:371:5) [capacitor] at boundsError (node:internal/buffer:86:9) [capacitor] at writeU_Int8 (node:internal/buffer:741:5) [capacitor] at Buffer.writeUInt8 (node:internal/buffer:748:10) [capacitor] at toCString (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:162:9) [capacitor] at AFCClient.openFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:52:9) [capacitor] at AFCClient.uploadFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:74:24) [capacitor] node:events:368 [capacitor] throw er; // Unhandled 'error' event

same here

@hinsxd
Copy link

hinsxd commented Sep 28, 2022

I got the same error. Please help!
[error] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 74. Received 75 [capacitor] at new NodeError (node:internal/errors:371:5) [capacitor] at boundsError (node:internal/buffer:86:9) [capacitor] at writeU_Int8 (node:internal/buffer:741:5) [capacitor] at Buffer.writeUInt8 (node:internal/buffer:748:10) [capacitor] at toCString (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:162:9) [capacitor] at AFCClient.openFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:52:9) [capacitor] at AFCClient.uploadFile (/Users/muhammadgul/dm-app/node_modules/native-run/dist/ios/lib/client/afc.js:74:24) [capacitor] node:events:368 [capacitor] throw er; // Unhandled 'error' event

same here

same, exactly the same error It must be >= 0 and <= 74. Received 75

@Schwankenson
Copy link

Same here RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 115. Received 116

@gianluigitrontini
Copy link

As stated by @cxcxcxcx,
a temporary fix is to open /node_modules/native-run/dist/ios/lib/client/afc.js and around line 160 change const buf = Buffer.alloc(s.length + 1); with const buf = Buffer.alloc(Buffer.byteLength(s) + 1);

Of course this is not a real solution, it will happen again as you run npm i. But it works until native-run gets updated.

@Martin-Eckleben
Copy link

Running into this now.
4 years old and open?

@hinsxd
Copy link

hinsxd commented Jul 16, 2023

We found out the error was caused by non-ascii characters in path names.

The s is some file path and please see the below result:

> Buffer.byteLength("—")
3
> "—".length
1

If you want to know which path is, run this file in the directory under investigation:

const fs = require("fs");
const path = require("path");

function* walkSync(dir) {
  const files = fs.readdirSync(dir, { withFileTypes: true });
  for (const file of files) {
    if (file.isDirectory()) {
      yield* walkSync(path.join(dir, file.name));
    } else {
      yield path.join(dir, file.name);
    }
  }
}

for (const filePath of walkSync(__dirname)) {
  if (Buffer.byteLength(filePath) != filePath.length) {
    console.log(filePath);
  }
}

Ref: https://stackoverflow.com/a/66083078

@zzxzzk115
Copy link

We found out the error was caused by non-ascii characters in path names.

The s is some file path and please see the below result:

> Buffer.byteLength("—")
3
> "—".length
1

If you want to know which path is, run this file in the directory under investigation:

const fs = require("fs");
const path = require("path");

function* walkSync(dir) {
  const files = fs.readdirSync(dir, { withFileTypes: true });
  for (const file of files) {
    if (file.isDirectory()) {
      yield* walkSync(path.join(dir, file.name));
    } else {
      yield path.join(dir, file.name);
    }
  }
}

for (const filePath of walkSync(__dirname)) {
  if (Buffer.byteLength(filePath) != filePath.length) {
    console.log(filePath);
  }
}

Ref: https://stackoverflow.com/a/66083078

Yeah, it works! I got the same error because there are some asset files named in Chinese characters. I can rename the files named in non-ASCII characters with the file you provided to solve the problem now. Thanks!

@negitoro001
Copy link

As stated by @cxcxcxcx, a temporary fix is to open /node_modules/native-run/dist/ios/lib/client/afc.js and around line 160 change const buf = Buffer.alloc(s.length + 1); with const buf = Buffer.alloc(Buffer.byteLength(s) + 1);

Of course this is not a real solution, it will happen again as you run npm i. But it works until native-run gets updated.

I try to const buf = Buffer.alloc(Buffer.byteLength(s) +1): however, i faced other error.

  • native-run: v1.7.3
  • Nuxt.js 3.8.0
  • capacitor: 5.5.0
Error: UNKNOWN_ERROR
        at AFCProtocolReader.callback
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/afc.js:277:54)
        at AFCProtocolReader.onData
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/protocol.js:53:26)
        at Socket.emit (node:events:517:28)
        at addChunk (node:internal/streams/readable:335:12)
        at readableAddChunk (node:internal/streams/readable:308:9)
        at Readable.push (node:internal/streams/readable:245:10)
        at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
        /Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/protocol.js:104
        throw err;
        ^
        
        Error [ERR_STREAM_WRITE_AFTER_END]: write after end
        at new NodeError (node:internal/errors:405:5)
        at _write (node:internal/streams/writable:322:11)
        at Writable.write (node:internal/streams/writable:337:10)
        at AFCProtocolWriter.write
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/afc.js:361:16)
        at
        /Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/afc.js:300:25
        at new Promise (<anonymous>)
        at AFCProtocolClient.sendMessage
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/protocol/afc.js:286:16)
        at AFCClient.closeFile
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/client/afc.js:64:36)
        at AFCClient.uploadFile
        (/Users/satakeryouta/kusurimiru_nuxt_v3/node_modules/.pnpm/native-run@1.7.3/node_modules/native-run/dist/ios/lib/client/afc.js:78:24)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
        code: 'ERR_STREAM_WRITE_AFTER_END'
        }
        
        Node.js v18.18.2

how is resolved it?

@dtarnawsky
Copy link
Contributor

To reproduce you can add this file to your assets of your app then call npx cap run ios.

Capacitor Engineering ⚡️ automation moved this from Backlog 🤖 to Done 🎉 Jan 25, 2024
@Ionitron
Copy link
Collaborator

🎉 This issue has been resolved in version 2.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.