【发布时间】:2019-12-31 21:39:03
【问题描述】:
我正在使用 Visual Studio 2019(带有 ASP.Net Core 3.1 Web API)的 React with Redux 教程,使用 Visual Studio 2019(版本 16.4.2)提供的标准 React with Redux 模板。
教程说要测试发布构建它的应用程序并将所有已发布的内容添加到 bin/Release 文件夹中,但由于单个文件中的导入语句,我无法使其工作。
除了添加一些 SCSS 支持并对其进行测试外,我没有在任何文件中编辑 ClientApp 文件夹内的任何代码,并且在 ASP.Net Core 代码中的 Startup 类中完成了最低限度的工作(我刚刚创建了一个基本的中间件组件记录响应和请求内容的 httpContext,所以我知道这不是问题)。
错误如下图:
31/12/19 07:54:14 PM
System.AggregateException: One or more errors occurred. ---> System.Exception: Build failed. Check the Output window for more details.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.WebTools.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass43_0.<PublishAsync>b__3()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Publish.Framework.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__156.MoveNext()
---> (Inner Exception #0) System.Exception: Build failed. Check the Output window for more details.<---
System.Exception: Build failed. Check the Output window for more details.
===================
从截图中可以看出,它指的是我的导入。例如:
找不到模块“../store”
指的是 FetchData.tsx 文件:
import { ApplicationState } from '../store';
其他 2 个错误是指 WeatherForecasts.ts 文件:
import { Action, Reducer } from "redux";
import { AppThunkAction } from './';
这是所有模板代码。我想知道它是否与相对路径有关,但不确定为什么这会不正确,因为没有任何改变,但是在 package.json 文件中指定了 redux 一个作为依赖项,就像其他包一样,所以我是不确定为什么这不起作用。
这是我的 package.json 文件以防万一:
{
"name": "example.web",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"connected-react-router": "6.5.2",
"history": "4.10.1",
"jquery": "^3.4.1",
"merge": "1.2.1",
"popper.js": "^1.16.0",
"react": "16.11.0",
"react-dom": "16.11.0",
"react-redux": "7.1.1",
"react-router": "5.1.2",
"react-router-dom": "5.1.2",
"react-scripts": "^3.2.0",
"reactstrap": "8.1.1",
"redux": "4.0.4",
"redux-thunk": "2.3.0",
"svgo": "1.3.0"
},
"devDependencies": {
"@types/history": "4.7.3",
"@types/jest": "24.0.19",
"@types/node": "12.11.6",
"@types/react": "16.9.9",
"@types/react-dom": "16.9.2",
"@types/react-redux": "7.1.5",
"@types/react-router": "5.1.2",
"@types/react-router-dom": "5.1.0",
"@types/reactstrap": "8.0.6",
"@typescript-eslint/parser": "^2.5.0",
"cross-env": "6.0.3",
"eslint": "^6.5.1",
"eslint-plugin-flowtype": "^3.13.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.16.0",
"typescript": "3.6.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "cross-env CI=true react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint ./src/**/*.ts ./src/**/*.tsx"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
tsconfig.json 文件:
{
"compilerOptions": {
"target": "es5",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"lib": [
"es2015",
"dom"
],
"skipLibCheck": false
},
"include": [
"src"
]
}
很抱歉,我无法提供整个应用程序,但是使用带有 ASP.Net Core 3.1 的 Visual Studio 2019 的标准 React 和 Redux 模板应该会导致相同的问题,因为这基本上是我为产生问题所做的一切。我该如何解决这个问题?谢谢。
编辑: 删除 package.lock.json 并删除 node_modules 并重新安装它们后,我得到了一个新错误:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build'
1 verbose cli ]
2 info using npm@6.12.0
3 info using node@v12.13.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle example.web@0.1.0~prebuild: example.web@0.1.0
6 info lifecycle example.web@0.1.0~build: example.web@0.1.0
7 verbose lifecycle example.web@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle example.web@0.1.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\<User>\Documents\example\example\example.Web\ClientApp\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\GitExtensions\;C:\Program Files\dotnet\;C:\Users\<User>\AppData\Local\Microsoft\WindowsApps;C:\Users\<User>\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\<User>\AppData\Roaming\npm;C:\ProgramData\Anaconda2\Scripts;C:\Users\<User>\.dotnet\tools
9 verbose lifecycle example.web@0.1.0~build: CWD: C:\Users\<User>\Documents\example\example\example.Web\ClientApp
10 silly lifecycle example.web@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
11 silly lifecycle example.web@0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle example.web@0.1.0~build: Failed to exec build script
13 verbose stack Error: example.web@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid example.web@0.1.0
15 verbose cwd C:\Users\<User>\Documents\example\example\example.Web\ClientApp
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v12.13.0
19 verbose npm v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error example.web@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the example.web@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
【问题讨论】:
-
我尝试了您的代码,但无法重现。但是,我多次看到
node_modules坏了。我总是完全删除node_modules/文件夹和package-lock.json文件,并确保手动运行npm i时没有错误。 -
@itminus 谢谢。我试过了,我收到了一条新的错误消息,但至少它不再抱怨不应该丢失的模块。似乎主要问题是
"Failed to exec build script" -
@itminus我解决了这个问题。我不得不从 package.json 中删除 node-sass 并使用
npm install node-sass和npm rebuild node-sass,因为它添加不正确。错误消息非常糟糕,其他人已经多次提到这一点。我也需要按照你的建议去做,我想。
标签: reactjs asp.net-core redux visual-studio-2019