2017-10-11 23 views
0

我已經使用Create-React-App初始化了一個項目。Create-React-App:Uncaught錯誤:無法找到模塊「./locale」

所有工作都OK,如果我...

npm run start和觀點上http://localhost:3000

npm run build && serve -s build和視圖上http://localhost:5000

但是當我部署到與S3桶...

npm run build && aws s3 sync build/ s3://${DEPLOYMENT_BUCKET}

...我去S3網址,並得到一個空白屏幕與此錯誤控制檯:

Uncaught Error: Cannot find module "./locale"

我想這可能是是與moment.js - 雖然它不是依賴我已經添加。

展望我node_modules我能看到的moment.js是2.18.1版本,我認爲規則出this answer

我不知道如何調試這個問題,所以任何幫助表示讚賞。

不知道這是否有幫助,但我目前的package.json如下。

{ 
    "name": "my_app", 
    "version": "1.0.0", 
    "private": true, 
    "dependencies": { 
    "amazon-cognito-identity-js": "^1.19.0", 
    "antd": "^2.13.4", 
    "axios": "^0.16.2", 
    "react": "^15.6.1", 
    "react-dom": "^15.6.1", 
    "react-router-dom": "^4.2.2", 
    "react-scripts": "1.0.13", 
    "recompose": "^0.25.1" 
    }, 
    "scripts": { 
    "start": "react-scripts start", 
    "build": "react-scripts build", 
    "test": "react-scripts test --env=jsdom", 
    "eject": "react-scripts eject" 
    } 
} 
+0

您是否嘗試過將momentJS添加爲顯式依賴項,以查看它是否修復了您的問題?至於爲什麼它被使用和丟失,它可能與你的建設過程有關,這在你的問題中沒有詳細說明。它可以用作你正在使用的軟件包中的一個軟件包的依賴項,然後在構建過程中被忽略。 – Jaxx

+0

多煩人 - 是增加時刻作爲依賴已修復它 - 乾杯@jaxx – Luke

+0

我給的答案根本沒有幫助?爲了您的緣故,我希望您在生成構建配置中註釋掉一行後,不必添加此依賴項。 – Jaxx

回答

0

尋找到的方式後反應的腳本處理項目的建設,我發現的代碼在/react-scripts/config/webpack.config.prod.js文件自帶的創造 - 反應 - 應用程序(這是督促建立的的WebPack配置文件)這個有趣的片段。

// Moment.js is an extremely popular library that bundles large locale files 
// by default due to how Webpack interprets its code. This is a practical 
// solution that requires the user to opt into importing specific locales. 
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack 
// You can remove this if you don't use Moment.js: 
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), 

你可能想要麼進口具體地點,如果你使用任何,它不會出現這樣的情況,或以其他方式註釋掉該行。