• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

import 사용 불가 문제

21.05.15 06:32 작성 조회수 133

0

웹팩 설정을 똑같이 한 것 같은데 require문은 사용이 가능한데 import 사용시 이와 같은 에러가 나옵니다.

webpack의 babel 옵션을 검색해보았으나 import to require 옵션을 찾기 힘들어 여기에 여쭤봅니다.

const path = require("path");
const RefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");

module.exports = {
  name: "tictactoe-dev",
  mode: "development", // publish option -> production
  devtool: "eval",
  resolve: {
    extensions: [".js", ".jsx"],
  },
  entry: {
    app: ["./client"], // already webpack knows about wordchain.jsx file
  }, // Input

  module: {
    rules: [
      {
        test: /\.jsx?/,
        loader: "babel-loader",
        options: {
          // Adding all browsers can affect performance, so adding only the browsers you want is important.
          // It also allows you to apply different options in detail
          // plugins are setting for preset
          presets: [
            [
              "@babel/preset-env",
              {
                targets: {
                  browsers: ["> 5% in KR", "last 2 chrome versions"], // browserslists
                },
                debug: true,
              },
            ],
            "@babel/preset-react",
          ],
          plugins: [
            "@babel/plugin-proposal-class-properties",
            "react-refresh/babel",
          ],
        },
      },
    ],
  },
  // extension, if you need to add more options
  // add debug in all module components
  // plugins: [new webpack.LoaderOptionsPlugin({ debug: true })],
  plugins: [new RefreshWebpackPlugin()],
  output: {
    path: path.join(__dirname, "dist"),
    filename: "app.js",
    publicPath: "/dist/",
  }, // Output
  devServer: {
    publicPath: "/dist/",
    hot: true,
  },
};

답변 1

답변을 작성해보세요.

0

import를 어떻게 쓰셨는지 코드 보여주세요. module.exports도 export default로 바꾸셨나요?

NOAH님의 프로필

NOAH

질문자

2021.05.15

네 둘다 그렇게 사용하였습니다. 확인 여러번 하였구요.

제로초님의 깃허브에 있는 "webpack.config.js" 파일 갖다 쓰니 그냥 잘 되네요..

바뀐 내용만 첨부하자면

위쪽이 제 원래 파일 아래쪽 내용이 제로초님 파일입니다.

지금보니 플러그인쪽 React를 빼먹어서 그런거 같은 느낌이 있네요.. 다시 보니 알겠습니다.

  plugins: [new RefreshWebpackPlugin()],
 plugins: [new ReactRefreshWebpackPlugin()],

  devtool: "inline-source-map",
 devtool: "eval",

plugins: [
            "@babel/plugin-proposal-class-properties",
            "react-refresh/babel",
          ],
plugins: ["react-refresh/babel"],