Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 错误:最终加载程序(./node_modules/awesome typescript loader/dist/entry.js)没有';t返回缓冲区或字符串_Reactjs_Typescript_Docker_Nginx_Webpack - Fatal编程技术网

Reactjs 错误:最终加载程序(./node_modules/awesome typescript loader/dist/entry.js)没有';t返回缓冲区或字符串

Reactjs 错误:最终加载程序(./node_modules/awesome typescript loader/dist/entry.js)没有';t返回缓冲区或字符串,reactjs,typescript,docker,nginx,webpack,Reactjs,Typescript,Docker,Nginx,Webpack,dockerhub生成dockerfile时发生此错误 错误:最终加载程序(./node\u modules/awesome typescript loader/dist/entry.js)未返回缓冲区或字符串 我在网上搜索了各种解决方案,但没有找到任何有效的 “网页包”:“^5.38.1” “出色的typescript加载程序”:“^5.2.1” 这是我的docker文件 # build environment FROM node:12.22.1-alpine as build WORKDIR

dockerhub生成dockerfile时发生此错误

错误:最终加载程序(./node\u modules/awesome typescript loader/dist/entry.js)未返回缓冲区或字符串

我在网上搜索了各种解决方案,但没有找到任何有效的

“网页包”:“^5.38.1” “出色的typescript加载程序”:“^5.2.1”

这是我的docker文件

# build environment
FROM node:12.22.1-alpine as build
WORKDIR /app
COPY package.json /app/package.json
RUN npm cache clean --force 
RUN npm install
COPY . /app
ENV PORT 80
ENV NODE_ENV=development
RUN npm run dev

# production environment
FROM nginx:stable-alpine
COPY nginx.test.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] 
tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "types": [
      "webpack-env"
    ],
    //"noImplicitThis": true,
    //"strictNullChecks": true
  },
  "awesomeTypescriptLoaderOptions": {
    "useTranspileModule": true,
  },
  "include": [
    "src",
    "src/.d.ts"
  ]
}
webpack.config.dev.js

const path = require('path');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const precss = require('precss');


module.exports = {
    mode: 'development',
    entry: './src/index.tsx',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].js',
        chunkFilename: '[name].[contenthash].js',
        publicPath: '/'
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    module: {
        rules: [
            {
                test: /\.js$|jsx/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    use: ['babel-loader']
                }
            },
            {
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.pdf$/i,
                use: 'file-loader',
            },
            {
                test: /\.(png|jpe?g|gif|svg)$/,
                use: 'url-loader?limit=10000&name=img/[name].[ext]'
            },
            {
                test: /\.tsx?$/,
                loader: 'awesome-typescript-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.s[ac]ss$/i,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader',
                ]
            },
            {
                test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'fonts/'
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: __dirname + '/public/index.html',
            filename: 'index.html',
            inject: 'body',
        }),
        new CopyWebpackPlugin({
            //this is the new change
            patterns: [
              { from: path.join(__dirname, 'static') },
            ],
      
          }),
        new webpack.LoaderOptionsPlugin({
            options: {
                postcss: [autoprefixer, precss],
            },
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
};

awesome typescript loader不再维护,并且与Webpack 5(或最新的typescript版本)不兼容。您需要删除
awesome typescript loader
,安装
ts loader
,并将
webpack.config.dev.js
中的相关块更改为:

{
测试:/\.tsx?$/,,
加载器:“ts加载器”,
排除:/node_模块/,
},