Я отлаживаю код VS 1.42.1 с помощью приложения React Native 0.61.5. Вот launch.json
:
"version": "0.2.0",
"configurations": [
{
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 9229
},
{
"type": "node",
"request": "launch",
"name": "Launch index.js",
"program": "${workspaceFolder}/emps_fe615\\index.js" //<<== here is the entry point
}
]
}
Однако на консоли отладки возникла ошибка:
C:\Program Files\nodejs\node.exe --inspect-brk=24899 emps_fe615\index.js
Debugger listening on ws://127.0.0.1:24899/1375f61a-e4a6-4f0f-b5fd-90b3b9d45d2a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Wc:\D\code\js\emps_fe615\index.js:5
import {AppRegistry} from 'react-native';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1072:16)
at Module._compile (internal/modules/cjs/loader.js:1122:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
aiting for the debugger to disconnect...
Вот index.js
:
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
Здесь является частью package.json
:
"dependencies": {
"@react-native-community/async-storage": "^1.8.0",
"@react-native-community/cli-platform-android": "^4.1.1",
"@react-native-community/datetimepicker": "^2.2.2",
"@react-native-community/masked-view": "^0.1.6",
"moment": "^2.24.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-audio": "^4.3.0",
"react-native-confirmation-code-field": "^5.1.0",
"react-native-confirmation-code-input": "^1.0.4",
"react-native-device-info": "^5.5.3",
"react-native-elements": "^1.2.7",
"react-native-gesture-handler": "^1.6.0",
"react-native-gifted-chat": "^0.13.0",
"react-native-image-picker": "^2.3.0",
"react-native-image-resizer": "^1.2.0",
"react-native-keychain": "^4.0.5",
"react-native-linear-gradient": "^2.5.6",
"react-native-modal": "^11.5.4",
"react-native-modal-datetime-picker": "^8.3.0",
"react-native-navbar": "^2.1.0",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.0.0-beta.10",
"react-native-segmented-control-tab": "^3.4.1",
"react-native-sound": "^0.11.0",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.1.1",
"react-navigation-tabs": "^2.7.0",
"socket.io-client": "2.1.1"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^0.0.7",
"babel-jest": "^25.1.0",
"eslint": "^6.8.0",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.58.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
Поскольку index.js
генерируется самим react-native
и никогда не изменялся. Я понятия не имею об этой ошибке.