添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
逃课的水龙头  ·  Bash shell,while ...·  10 月前    · 
文武双全的蚂蚁  ·  database - One To ...·  1 年前    · 
爱笑的马铃薯  ·  node_modules/tslib/tsl ...·  1 年前    · 
解决build问题TypeScript error in /X/node_modules/@types/babel__traverse/index.d.ts Type expected. TS1110
最新推荐文章于 2024-07-19 14:22:37 发布
最新推荐文章于 2024-07-19 14:22:37 发布 阅读量 1.1k
一个几年没有动过的前端工程,上次发布成功还是在21年,过去了3年,现在在docker中对前端工程进行build的时候,一直报一个错误:
#13 127.9 Creating an optimized production build...
#13 293.5 Failed to compile.
#13 293.5 
#13 293.5 /finance_core_frontend/node_modules/@types/babel__traverse/index.d.ts
#13 293.5 TypeScript error in /finance_core_frontend/node_modules/@types/babel__traverse/index.d.ts(314,13):
#13 293.5 Type expected.  TS1110
#13 293.5 
#13 293.5     312 |         // too complex for TS. So we type it as a general visitor only if the key contains `|`
#13 293.5     313 |         // this is good enough for non-visitor traverse options e.g. `noScope`
#13 293.5   > 314 |         [k: `${string}|${string}`]: VisitNode<S, Node>;
#13 293.5         |             ^
#13 293.5     315 |     };
#13 293.5     316 | 
#13 293.5     317 | export type VisitNode<S, P extends Node> = VisitNodeFunction<S, P> | VisitNodeObject<S, P>;
#13 293.5 
#13 293.5 
#13 293.6 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#13 293.6 error Command failed with exit code 1.
#13    completed: 2024-03-05 08:51:16.276493854 +0000 UTC
#13     duration: 4m54.10665194s
#13        error: "process \"/bin/sh -c yarn && yarn build\" did not complete successfully: exit code: 1"
process "/bin/sh -c yarn && yarn build" did not complete successfully: exit code: 1
Build step 'Execute shell' marked build as failure
Finished: FAILURE

package.json如下:

"name": "XXXX", "homepage": "XXXX", "version": "0.1.0", "private": true, "dependencies": { "@ant-design/icons": "^4.2.1", "@ant-design/icons-react": "^2.0.1", "@craco/craco": "^5.6.4", "@reduxjs/toolkit": "^1.4.0", "@testing-library/jest-dom": "^5.11.1", "@testing-library/react": "^10.4.7", "@testing-library/user-event": "^12.0.11", "@types/echarts": "^4.6.3", "@types/history": "^4.7.6", "@types/jest": "^26.0.4", "@types/node": "^14.0.23", "@types/numeral": "^0.0.28", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", "@types/react-redux": "^7.1.9", "@types/react-router-dom": "^5.1.5", "antd": "^4.4.1", "axios": "^0.19.2", "craco-less": "^1.17.0", "echarts": "^4.8.0", "echarts-for-react": "^2.0.16", "eusjs": "^1.1.3", "http-proxy-middleware": "^1.0.6", "numeral": "^2.0.6", "rc-banner-anim": "^2.4.4", "react": "^16.13.1", "react-document-title": "^2.0.3", "react-dom": "^16.13.1", "react-redux": "^7.2.0", "react-router-dom": "^5.2.0", "react-scripts": "3.4.1", "redux-persist": "^6.0.0", "redux-thunk": "^2.3.0", "typescript": "^3.9.6" "scripts": { "start": "craco start", "build": "craco build", "test": "craco test", "eject": "react-scripts eject" "eslintConfig": { "extends": "react-app" "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version"

dockerfile如下:

# stage: 1
FROM node:14.15 as react-build
WORKDIR /finance_core_frontend
COPY . ./
RUN yarn && yarn build
# Stage 2 - the production environment
FROM nginx:alpine
#更改容器时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=react-build /finance_core_frontend/build /usr/share/nginx/html
RUN chmod -R o+r /usr/share/nginx/html
EXPOSE 3600
CMD ["nginx", "-g", "daemon off;"]

查了很久的资料,终于解决了,原因是typescript 和 react-script的版本有冲突导致的:

[@types/babel__traverse] Type Expected issue with @types/babel__traverse package · Issue #65766 · DefinitelyTyped/DefinitelyTyped · GitHub

关键还是下面这哥们的一句话:

将react-script的版本, "react-scripts": "3.4.1", 改成4.0.3,解决了问题。

特此记录

angular项目运行时报错 ERROR in node_modules/ng-zorro-antd/empty/nz-embed-empty.component.d.ts(17,17): error TS1110: Type expected. node_modules/ng-zorro-antd/empty/nz-empty.component.d.ts(11,17): error TS111... TypeScript err in xxx/@node_models/@types/babel__traverse/index.d.ts:']' expected . TS1005 错误信息列表code类型英文描述中文描述1002错误Unterminated string literal.未终止的字符串文本。1003错误Identifier expected.应为标识符。1005错误'{0}' expected.应为“{0}”。1006错误A file cannot have a reference to itself.文件不能引用自身。1009错误Trailing comm... React配置 webpack多页应用打包失败,报错Cannot read property ‘filter’ of undefined解决方案 react的多页应用,运行 npm run build 后控制台报错: npm run build node scripts/build.js Creating an optimized production build... Failed to compile. Cannot read property 'filter' of undefined 控制台并没 问题:npm run build在window平台构建成功,liunx平台失败步骤:在项目根目录执行npm install 执行成功在根目录执行npm run build报错报错信息如下:Creating an optimized production build...Failed to compile.Module not found: Error: Can't resolve 'React' ... charCodeAt() 返回在指定的位置的字符的 Unicode 编码。 concat() 连接两个或更多字符串,并返回新的字符串。 fromCharCode() 将 Unicode 编码转为字符。 indexOf() 返回某个指定的字符串值在字符串中首次出现的位置。 includes() 查找字符串中是否包含指定的子字符串。 lastIndexOf() 从后向前搜索字符串,并从起始位置(0)开始计算返回字符串最后出现的位置。 Creating an optimized production build... Treating warnings as errors because process.env.CI = true. Most CI servers set it a