trtc-electron-sdk
compatible with Electron v12.0.1?Yes, it is. trtc-electron-sdk
does not rely on the SDK of Electron and therefore does not have version requirements.
Type the following command in the terminal
$ npm config set electron_custom_dir 8.1.1 # Determined by the actual version number
Solution:
Go to the directory of trtc-electron-sdk
(xxx/node_modules/trtc-electron-sdk) in your project and run the following command:
npm run install -- arch=ia32
Download the 32-bit trtc_electron_sdk.node
and build your project again.
You need to request access to the camera from VS Code. Use the code below:
cd ~/Library/Application\ Support/com.apple.TCC/
cp TCC.db TCC.db.bak
sqlite3 TCC.db # sqlite> prompt appears.
# for Mojave, Catalina
INSERT into access VALUES('kTCCServiceCamera',"com.microsoft.VSCode",0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);
# for BigSur
INSERT into access VALUES('kTCCServiceCamera',"com.microsoft.VSCode",0,1,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);
Solution:
Context isolation is enabled by default in Electron 12. Disable it by setting contextIsolation
to false
.
let win = new BrowserWindow({
width: 1366,
height: 1024,
minWidth: 800,
minHeight: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
});
This issue should be dealt with case by case. Possible causes include:
After download, when you run your project, the following error may occur in the terminal:
Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
Follow the steps below to manually download Electron:
npm config get cache
to view the cache path.npm install
again.If you launch your project using the VS Code terminal, the process may crash when the SDK starts the camera and mic:
csrutil disable
.csrutil enable
in step 2.When you run your project, Electron may report the error “xx is not defined” in the console (xx
is the node module):
Uncaught ReferenceError: require is not defined
Set nodeIntegration
to true
in the main.js
file of Electron:
let win = new BrowserWindow({
width: 1366,
height: 1024,
webPreferences: {
nodeIntegration: true, // Set it to `true`
},
});
You may see one of the following error messages when running your project after compilation:
NodeRTCCloud is not a constructor
Cannot open xxx/trtc_electron_sdk.node
or The specified module could not be found
dlopen(xxx/trtc_electron_sdk.node, 1): image not found
The errors indicate that the trtc_electron_sdk.node
module hasn’t been built into your project successfully. To fix the problem, follow these steps:
native-ext-loader
. $ npm i native-ext-loader -D
module.exports
to pass the --target_platform
command line parameter to webpack.config.js
so that your project can be packaged correctly for its target platform.const os = require('os');
// If you don’t pass `target_platform`, your project will be packaged for the current platform.
const targetPlatform = (function(){
let target = os.platform();
for (let i=0; i<process.argv.length; i++) {
if (process.argv[i].includes('--target_platform=')) {
target = process.argv[i].replace('--target_platform=', '');
break;
}
}
// `win32` indicates Windows, including 32-bit and 64-bit. `darwin` indicates macOS.
if (!['win32', 'darwin'].includes) target = os.platform();
return target;
})();
module: {
rules: [
{
test: /\.node$/,
loader: 'native-ext-loader',
options: {
rewritePath: targetPlatform === 'win32' ? './resources' : '../Resources'
}
},
]
}
Note:
- If you create your project with
vue-cli
, webpack configuration can be found in theconfigureWebpack
option ofvue.config.js
.- If you create your project with
create-react-app
, the path to the webpack configuration file is[Project directory]/node_modules/react-scripts/config/webpack.config.js
.
packages.json
.electron-builder
(case sensitive):"build": {
"Omit": "...",
"win": {
"extraFiles": [
{
"from": "node_modules/trtc-electron-sdk/build/Release/",
"to": "./resources",
"filter": ["**/*"]
}
]
},
"mac": {
"extraFiles": [
{
"from": "node_modules/trtc-electron-sdk/build/Release/trtc_electron_sdk.node",
"to": "./Resources"
}
]
},
"directories": {
"output": "./bin"
}
},
create-react-app
, add building and packaging scripts as follows:"scripts": {
"build:mac": "react-scripts build --target_platform=darwin",
"build:win": "react-scripts build --target_platform=win32",
"compile:mac": "node_modules/.bin/electron-builder --mac",
"compile:win64": "node_modules/.bin/electron-builder --win --x64",
"pack:mac": "npm run build:mac && npm run compile:mac",
"pack:win64": "npm run build:win && npm run compile:win64"
}
vue-cli
, add building and packaging scripts as follows:"scripts": {
"build:mac": "vue-cli-service build --target_platform=darwin",
"build:win": "vue-cli-service build --target_platform=win32",
"compile:mac": "node_modules/.bin/electron-builder --mac",
"compile:win64": "node_modules/.bin/electron-builder --win --x64",
"pack:mac": "npm run build:mac && npm run compile:mac",
"pack:win64": "npm run build:win && npm run compile:win64"
}
When you use electron-builder
to build a project created with create-react-app
, the following error may occur:
$ node_modules\.bin\electron-builder.cmd
• electron-builder version=22.6.0 os=6.1.7601
• loaded configuration file=package.json ("build" field)
• public/electron.js not found. Please see https://medium.com/@kitze/%EF%B8%8F-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3
• loaded parent configuration preset=react-cra
public/electron.js not found
indicates that the entry point file was not found.
$ cd [Project directory]
$ mv main.electron.js ./public/electron.js
pacakge.json
file:{
"main": "public/electron.js",
"Omit": "..."
}
fs-extra
module occurs during packaging?[Project directory]\node_modules\electron-builder\node_modules\fs-extra\lib\empty\index.js:33
} catch {
^
SyntaxError: Unexpected token {
at new Script (vm.js:51:7)
Update to the latest version of Node.
Was this page helpful?