{"id":431145,"date":"2021-04-18T11:35:44","date_gmt":"2021-04-18T03:35:44","guid":{"rendered":"http:\/\/4563.org\/?p=431145"},"modified":"2021-04-18T11:35:44","modified_gmt":"2021-04-18T03:35:44","slug":"%e6%9c%89%e4%bb%80%e4%b9%88%e5%8a%9e%e6%b3%95%e8%83%bd%e5%a4%9f%e5%9c%a8-react-%e4%b8%ad%e4%bd%bf%e7%94%a8-import-%e5%af%bc%e5%85%a5-nodejs-%e6%a8%a1%e5%9d%97%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=431145","title":{"rendered":"\u6709\u4ec0\u4e48\u529e\u6cd5\u80fd\u591f\u5728 React \u4e2d\u4f7f\u7528 import \u5bfc\u5165 nodejs \u6a21\u5757\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u4ec0\u4e48\u529e\u6cd5\u80fd\u591f\u5728 React \u4e2d\u4f7f\u7528 import \u5bfc\u5165 nodejs \u6a21\u5757\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Yukee798 <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u5728\u7528 React + Electron + ts \u5199 App\uff0c\u6709\u9700\u6c42\u8981\u7528\u5230 nodejs \u91cc\u9762\u7684 fs \u6a21\u5757\uff0c\u4e86\u89e3\u5230\u4e86\u51e0\u79cd\u5bfc\u5165\u65b9\u5f0f\u3002<\/p>\n<pre><code>\/\/ \u8fd9\u6837\u5bfc\u5165\u4f1a\u62a5\u9519\uff1aModule not found: Can't resolve 'fs'\uff0c\u4f46\u662f\u6709\u4ee3\u7801\u63d0\u793a import * as fs from 'fs';  \/\/ \u4f7f\u7528 require \u5bfc\u5165 \/\/ \u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u4f46\u662f\u6ca1\u6709\u4ee3\u7801\u63d0\u793a const fs = window.require('fs'); <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5673118\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : learningman <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b2c\u4e8c\u4e2a\u52a0\u4e2a as Node.fs \u8bd5\u8bd5\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5673119\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yukee798 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @learningman Node \u4e0b\u9762\u6709\u7ea2\u7ebf\uff1a&#8217;Node&#8217; only refers to a type, but is being used as a namespace here.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5673120\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : otakustay <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ee5\u524d\u6709 remote \u6a21\u5757\uff0c\u73b0\u5728\u6ca1\u4e86\uff0c\u4f60\u7684\u9700\u6c42\u641e\u4e0d\u5b9a\u7684\uff0c\u53ea\u80fd\u8d70 ipc \u627e main \u7ebf\u7a0b\u641e\u4e8b\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5673121\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jianzhihao1996 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             electron \u662f\u5426\u6709\u542f\u7528 nodeIntegration \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5673122\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhuweiyou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6b63\u786e\u7684\u59ff\u52bf\u4e0d\u662f ipc ?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4ec0\u4e48\u529e\u6cd5\u80fd\u591f\u5728 React \u4e2d\u4f7f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/431145"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=431145"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/431145\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=431145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=431145"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=431145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}