前提・実現したいこと
- Next.js上でのreact-calendarの動作
Next.js上でreact-calendarを動作させたいです。
ビルドの際に下記エラーメッセージが表示されます。
発生している問題・エラーメッセージ
❯ yarn build yarn run v1.21.1 $ next build Creating an optimized production build Failed to compile. ./node_modules/react-calendar/dist/Calendar.css 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > .react-calendar { | width: 350px; | max-width: 100%; > Build error occurred Error: > Build failed because of webpack errors at build (~/myActivity/study/react/nextJS/react-calendar/node_modules/next/dist/build/index.js:10:900) at <anonymous> error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
該当のソースコード
json
1{ 2 "name": "react-calendar", 3 "version": "1.0.0", 4 "main": "index.js", 5 "license": "MIT", 6 "dependencies": { 7 "next": "^9.1.7", 8 "react": "^16.12.0", 9 "react-calendar": "^2.19.2", 10 "react-dom": "^16.12.0" 11 }, 12 "scripts": { 13 "dev": "next", 14 "build": "next build", 15 "start": "next start" 16 } 17}
js
1// next.config.js 2module.exports = { 3 transpileModules: ["react-calendar"] 4}; 5 6// pages/index.js 7import React, { useState } from "react"; 8import Calendar from "react-calendar"; 9 10const Index = () => { 11 [date, setDate] = useState(new Date()); 12 return ( 13 <div> 14 <Calendar onChange={setDate} value={date} /> 15 </div> 16 ); 17}; 18 19export default Index;
試したこと
node_moduleでNext.jsでのトランスパイルが実行されていないことが原因と考え、
こちらを参考にnext.config.jsの設定を追記した。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/12 15:14