Reactを使ってChrome拡張機能の作成をしております。
create-react-app で雛形を作成し、徐々に既存のファイルを追加しながら開発したいと考えていたのですが、
表題のとおり chrome.runtime.sendMessage() を呼び出すところで未定義エラーが出てしまい、ビルドできません。 Reactのsrcディレクトリにchromeが存在しないのでエラーが出る理由はわかるのですが、解決方法がわかりません。chromeなどの外部の関数を呼出してもビルドできる方法はないでしょうか?
不足の情報などありましたら、適宜追記していきますので何卒よろしくお願いたします。
App.js
javascript
1 2function App() { 3 return ( 4 <div className="App"> 5 <div> 6 <button onClick={() => { login() }}><h1>Login</h1></button> 7 </div> 8 </div> 9 ); 10} 11 12function login() { 13 chrome.runtime.sendMessage( 14 { type: MESSAGE_TYPE.LOGIN1 }, 15 function (response) { 16 console.log(response); 17 }); 18}
エラーメッセージ
$ yarn build yarn run v1.15.2 $ react-scripts build Creating an optimized production build... Failed to compile. ./src/App.js Line 25: 'chrome' is not defined no-undef Search for the keywords to learn more about each error. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/07 05:32