2017-04-26 138 views
0

我正在構建一個Electron應用程序,我使用的是webContents.executeJavaScipt(),它幾乎是Electron瀏覽器的eval()。es6 eval模板字符串中缺少斜槓模板字符串:僅用於轉義問題

module.js:472 Uncaught Error: Cannot find module 'C:UsersMichael Bruce AllenDocumentsGitHubschedule-crawl 
enderer 
emoteItems.js' 
    at Module._resolveFilename (module.js:470:15) 
    at Function.Module._resolveFilename (C:\Users\Michael Bruce Allen\Documents\GitHub\schedule-crawl\node_modules\electron\dist\resources\electron.asar\common\reset-search-paths.js:35:12) 
    at Function.Module._load (module.js:418:25) 
    at Module.require (module.js:498:17) 
    at require (internal/module.js:20:19) 
    at <anonymous>:3:25 
    at EventEmitter.electron.ipcRenderer.on (C:\Users\Michael Bruce Allen\Documents\GitHub\schedule-crawl\node_modules\electron\dist\resources\electron.asar\renderer\init.js:52:28) 
    at emitMany (events.js:127:13) 
    at EventEmitter.emit (events.js:201:7) 

對我來說,似乎是一個逃避問題,對我說:直到我們把這個計劃我的客戶在Windows計算機上,這是錯誤我從來沒有問題。所以,我打破了這下儘可能的簡單,我想知道這裏發生了什麼:

const path = require('path'); 

const projectPath = ` 
    console.log('${path.join(__dirname, "project_path")}'); 
`; 

eval(projectPath); 

我得到WINDOWS:(顯然是錯誤的)

C:UsersMichael Bruce AllenDocumentsGitHubsandboxproject

在Linux上:(看上去很美)

/home/codeamend/Coding/projects/work/upwork/schedule-crawl/journal/learning/project_path

回答

0

嗯,事實證明,有時你只需要知道什麼類型的關鍵字用於搜索谷歌和找到你的答案。

發生了什麼事情是Windows \正在逃離角色。儘管我知道這樣的事情正在發生,但我不明白爲什麼。原來this stackexchange post幫我找到了答案。

這並不像我想要的那麼漂亮,所以我會將我的實際項目重構爲另一個不太冒險的解決方案。

const path = require('path'); 

const projectPath = ` 
    console.log(${JSON.stringify(path.join(__dirname, "project_path"))}); 
`; 

eval(projectPath);