Electron: λ¦¬μ†ŒμŠ€ λ‘œλ“œ μ‹€νŒ¨: net::ERR_FILE_NOT_FOUND file:///D:/css/app.css

에 λ§Œλ“  2015λ…„ 05μ›” 25일  Β·  26μ½”λ©˜νŠΈ  Β·  좜처: electron/electron

μ‘μš© ν”„λ‘œκ·Έλž¨μ— λ‹€μŒκ³Ό 같은 ꡬ쑰가 μžˆμŠ΅λ‹ˆλ‹€.
file struct

λ‚˜λŠ” 머리에 index.html을 μ“΄λ‹€.

<link rel="stylesheet" href="css/app.css"/>

μ „μžλ₯Ό μ‹€ν–‰ν•˜κ³  였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

capture
λ¦¬μ†ŒμŠ€ λ‘œλ“œ μ‹€νŒ¨: net::ERR_FILE_NOT_FOUND file:///D:/css/app.css
λͺ¨λ‘λ“€ λ§ν•΄μ£Όμ„Έμš”. 파일의 경둜λ₯Ό μ–΄λ–»κ²Œ μ„€μ •ν•΄μ•Ό ν•˜λ‚˜μš”?

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

ν•„μš”ν•˜λ©΄μ΄ λ¬Έμ œκ°€ λ°œμƒν•  경우 <base href="/"> 된 index.html에 λΆˆκ³Όν•˜μ—¬ ꡐ체 <base href="./"> .

λͺ¨λ“  26 λŒ“κΈ€

κ΄€λ ¨ 문제: #1747.

이 경둜 문제λ₯Ό ν•΄κ²°ν•˜λŠ” λ‹€λ₯Έ λ°©λ²•μœΌλ‘œ 이것을 μ‹œλ„ν•˜μ‹­μ‹œμ˜€.

<html>
  <head>
    <title></title>
  </head>
  <body>
    <script>
    var link = document.createElement('link')
    link.setAttribute('rel', 'stylesheet')
    link.setAttribute('href', require('path').join(__dirname, 'css', 'app.css'))
    document.head.appendChild(link)
    </script>
  </body>
</html>

@shama μŠ€λ‹ˆνŽ« κ°μ‚¬ν•©λ‹ˆλ‹€.
이 였λ₯˜κ°€ μ—†μœΌλ©΄ <base href="/">λ₯Ό μ‚¬μš©ν•˜κΈ° λ•Œλ¬Έμ— 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.
μƒ˜ν”Œ μž‘μ—… https://github.com/RinatMullayanov/angular-boilerplate λΆ„κΈ° μ „μž .

같은 λ¬Έμ œλ„ μžˆμŠ΅λ‹ˆλ‹€. Electron은 C:/ μ—μ„œ λ¦¬μ†ŒμŠ€λ₯Ό λ‘œλ“œν•˜λ €κ³  ν•˜λ©° μƒλŒ€ κ²½λ‘œκ°€ μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
전체 경둜 섀정은 μ˜΅μ…˜μ΄ μ•„λ‹ˆλ©° λ‹€λ₯Έ κ²½λ‘œμ— μ‘μš© ν”„λ‘œκ·Έλž¨μ„ λ°°μΉ˜ν•˜λ©΄ 파일이 λ‘œλ“œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

일뢀 글꼴을 μ–»λŠ” 것과 λ™μΌν•œ λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€.

λ‚΄ CSS에 이것을 μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.
<strong i="7">@import</strong> url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
λ‚˜λŠ” 이것을 λ‚΄ html에 μΆ”κ°€ν•˜λ €κ³  μ‹œλ„ν–ˆμŠ΅λ‹ˆλ‹€.
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />

λ‚˜λŠ” λ˜ν•œ μ‹œλ„ν–ˆλ‹€ :

<link rel="stylesheet" type="text/css" href="http//fonts.googleapis.com/css?family=Open+Sans" />

<link rel="stylesheet" type="text/css" href="https//fonts.googleapis.com/css?family=Open+Sans" />

ν•˜μ§€λ§Œμ΄ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.
Failed to load resource: net::ERR_CONNECTION_REFUSED

ν•„μš”ν•˜λ©΄μ΄ λ¬Έμ œκ°€ λ°œμƒν•  경우 <base href="/"> 된 index.html에 λΆˆκ³Όν•˜μ—¬ ꡐ체 <base href="./"> .

@Myrga 당신은 생λͺ…을 κ΅¬ν–ˆμŠ΅λ‹ˆλ‹€. λ‚˜λŠ”μ΄ 였래된 κ²Œμ‹œλ¬Όμ„ 발견 ν•  λ•ŒκΉŒμ§€ 5 일 λ™μ•ˆ 닡변을 μ°Ύκ³  μžˆμ—ˆκ³  이에 λŒ€ν•œ λ¬Έμ„œλŠ” μ—†μŠ΅λ‹ˆλ‹€. 정말 κ°μ‚¬ν•©λ‹ˆλ‹€

ps: μ—¬κΈ° μ™€μ„œ create-react-app을 μ‚¬μš©ν•˜κ³  μžˆλ‹€λ©΄ package.json에 "homepage": "./", λ₯Ό λ„£μ–΄λ³΄μ„Έμš”. (λΆ„λͺ…νžˆ 이것은 ν˜„μž¬ μ§€μ›λ˜μ§€ μ•ŠμœΌλ―€λ‘œ κΈ€κΌ΄ 등에 λ‹€λ₯Έ λ¬Έμ œκ°€ μžˆμ„ 수 μžˆμœΌλ―€λ‘œ ν•΄λ‹Ή μžμ‚°μ„ /public ν΄λ”λ‘œ 이동해야 ν•  수 있음)

맀우 κ°μ‚¬ν•©λ‹ˆλ‹€

@BesatZardosht URL에 μ˜€νƒ€κ°€ μžˆμŠ΅λ‹ˆλ‹€.

<link rel="stylesheet" type="text/css" href="https//fonts.googleapis.com/css?family=Open+Sans" />

ν•΄μ•Όν•œλ‹€:

<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans" />

( : )

Webpack 2.x , React 및/λ˜λŠ” Redux μ‚¬μš©ν•˜μ—¬ λ™μΌν•œ λ¬Έμ œκ°€ μžˆλŠ” 경우 이것이 문제λ₯Ό ν•΄κ²°ν•  κ°€λŠ₯성이 μžˆμŠ΅λ‹ˆλ‹€.

ν”„λ‘œμ νŠΈ λ””λ ‰ν† λ¦¬μ—μ„œ "publicPath"λ₯Ό κ²€μƒ‰ν•˜κ³  값을 / μ—μ„œ ./
λͺ¨λ“  μ‚¬μš© κ°€λŠ₯ν•œ λ‹€λ₯Έ boilerplates으둜이 섀정은 λ‚΄ 경우 μ‚¬μš©μ—μ„œ, μ„œλ‘œ λ‹€λ₯Έ μœ„μΉ˜μ—μ„œ 찾을 μˆ˜μžˆλ‹€ redux-cli μ‚¬μš©ν•˜λŠ”μ„ redux-starter-kit , κ·Έκ²ƒμ€μ΄μ—ˆλ‹€ project.config.js :

publicPath: './',

λ˜ν•œ Electron 용으둜 λΉŒλ“œν•˜λŠ” 경우 Webpack target 속성을 μΆ”κ°€/μˆ˜μ •ν•΄μ•Ό ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
ν–‰λ³΅ν•˜μ„Έμš”!! πŸ˜„

같은 λ¬Έμ œκ°€ μžˆμ—ˆμ§€λ§Œ Myrga의 μ†”λ£¨μ…˜μ΄ νš¨κ³Όκ°€ μžˆμ—ˆμŠ΅λ‹ˆλ‹€. 제 μƒκ°μ—λŠ” 파일 ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•  λ•Œ /λ₯Ό PC의 μ „μ—­ 루트 λ””λ ‰ν„°λ¦¬λ‘œ κ°„μ£Όν•΄μ•Ό ν•©λ‹ˆλ‹€. "./"λŠ” ν˜„μž¬ 폴더에 λŒ€ν•œ μƒλŒ€ 참쑰둜 μž‘λ™ν•©λ‹ˆλ‹€. 포트 4200(λ‚΄ Angular4 앱을 μ œκ³΅ν•˜λŠ” κ³³)μ—μ„œ http:// ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•  λ•Œ λͺ¨λ“  것이 "/"와 ν•¨κ»˜ μž‘λ™ν•©λ‹ˆλ‹€. 파일 ν”„λ‘œν† μ½œμ˜ 경우 "./"λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.

Reactμ—μ„œ λ‚΄ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ λ‹€μ‹œ λ§Œλ“€κΈ°λ‘œ κ²°μ •ν–ˆμŠ΅λ‹ˆλ‹€. λ‚΄ ν”„λ‘œμ νŠΈμ— 파일 λ‘œλ”λ₯Ό μΆ”κ°€ν•˜λ©΄ 이 λ¬Έμ œκ°€ λ‹€μ‹œ λ°œμƒν•˜κΈ° μ‹œμž‘ν–ˆμŠ΅λ‹ˆλ‹€. webpack.config.js의 publicPath 속성을 μƒλŒ€ 경둜(μ €μ˜ 경우 /app/κ°€ μ•„λ‹Œ ./app/)둜 λ³€κ²½ν•˜λ©΄ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

PSλŠ” 개발자 μ„œλ²„κ°€ 이것을 μ‹«μ–΄ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. 이 변경을 μˆ˜ν–‰ν•˜κ³  webpack dev μ„œλ²„λ₯Ό μ‹€ν–‰ν•˜λ €λŠ” 경우 이 λ³€κ²½μœΌλ‘œ 인해 ν˜Όλ™λ  κ²ƒμž…λ‹ˆλ‹€. μ „μžμ—μ„œ 직접 μž‘μ—…ν•˜κ³  dev μ„œλ²„μ—μ„œ μž‘μ—…ν•  λ•Œ μ•žλ’€λ‘œ μ „ν™˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.

html νŒŒμΌμ„ "μ›Ή νŽ˜μ΄μ§€λ‘œ μ €μž₯"으둜 μ €μž₯ν•œ λ‹€μŒ ν¬λ‘¬μ—μ„œ μ—΄μ–΄λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.
이것은 λ‚˜λ₯Ό μœ„ν•΄ μΌν–ˆμŠ΅λ‹ˆλ‹€.

" μžμ›μ„ λ‘œλ“œν•˜μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€: net::ERR_FILE_NOT_FOUND "λ₯Ό ν•΄κ²°ν•˜λŠ” 방법
"CSS"λ₯Ό μ‚¬μš©ν•˜μ—¬ 이미지λ₯Ό μΆ”κ°€ν•  λ•Œλ§ˆλ‹€ 이 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€. ν˜Ήμ‹œ ν•΄κ²° 방법 μžˆμœΌμ‹ κ°€μš”???
μ΄λ―Έμ§€λΏλ§Œ μ•„λ‹ˆλΌ κΈ€κΌ΄ 파일과 같은 νŒŒμΌμ—μ„œλ„ λ™μΌν•œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

@sunsun_sssssss @sssssssssss
λͺ¨λ“  파일이 μƒλŒ€ μ•± κ²½λ‘œκ°€ μ•„λ‹Œ 둜컬 파일 μ‹œμŠ€ν…œμ—μ„œ 제곡되기 λ•Œλ¬Έμž…λ‹ˆλ‹€.
해결책은 파일 ν”„λ‘œν† μ½œμ„ κ°€λ‘œμ±„λŠ” κ²ƒμž…λ‹ˆλ‹€. main.js νŒŒμΌμ—μ„œ λ‹€μŒ 변경을 μˆ˜ν–‰ν•˜μ‹­μ‹œμ˜€.

메인.js

mainWindow = new BrowserWindow({width: 1100, height: 700, icon: __dirname + '/icon.ico'}) mainWindow.loadURL(url.format({ pathname:'index.html', protocol: 'file', slashes: true }))

app.on('ready', () => { protocol.interceptFileProtocol('file', (request, callback) => { const url = request.url.substr(7) /* all urls start with 'file://' */ callback({ path: path.normalize( ${__dirname}/${url} )}) }, (err) => { if (err) console.error('Failed to register protocol') }) createWindow() /* callback function */ })

NS

@sunsun_sssssss @sssssssssss
λͺ¨λ“  파일이 μƒλŒ€ μ•± κ²½λ‘œκ°€ μ•„λ‹Œ 둜컬 파일 μ‹œμŠ€ν…œμ—μ„œ 제곡되기 λ•Œλ¬Έμž…λ‹ˆλ‹€.
해결책은 파일 ν”„λ‘œν† μ½œμ„ κ°€λ‘œμ±„λŠ” κ²ƒμž…λ‹ˆλ‹€. main.js νŒŒμΌμ—μ„œ λ‹€μŒ 변경을 μˆ˜ν–‰ν•˜μ‹­μ‹œμ˜€.

메인.js

mainWindow = new BrowserWindow({width: 1100, height: 700, icon: __dirname + '/icon.ico'}) mainWindow.loadURL(url.format({ pathname:'index.html', protocol: 'file', slashes: true }))

app.on('ready', () => { protocol.interceptFileProtocol('file', (request, callback) => { const url = request.url.substr(7) /* all urls start with 'file://' */ callback({ path: path.normalize( ${__dirname}/${url} )}) }, (err) => { if (err) console.error('Failed to register protocol') }) createWindow() /* callback function */ })

?

경둜 문제. λΈŒλΌμš°μ €λŠ” D:/css/app.cssμ—μ„œ νŒŒμΌμ„ κ²€μƒ‰ν•©λ‹ˆλ‹€. 이것은 μ½”λ“œ μ–΄λ”˜κ°€μ—μ„œ 잘λͺ»λœ 경둜λ₯Ό μ–ΈκΈ‰ν–ˆκΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€. /css/...와 같은 κ²½λ‘œκ°€ 주어지면 D:/μ—μ„œ κ²€μƒ‰λ©λ‹ˆλ‹€.

이것은 λ˜ν•œ νŠΈλ¦­μ„ μˆ˜ν–‰ν–ˆμŠ΅λ‹ˆλ‹€. 톡찰λ ₯을 μ£Όμ‹  @itsaakashpatel μ”¨μ—κ²Œ κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

// ...
const { protocol } = require('electron')
// ... 
// run the next block right before <BrowserWindow>.loadFile()
const htmlRootDir = 'dist/'
const indexFile = 'index.html'

protocol.interceptFileProtocol(
    'file',
    (request, callback) => {
        const url = request.url.substr(7) // strip "file://" out of all urls
        if (request.url.endsWith(indexFile)) {
            callback({ path: url })
        } else {
            callback({ path: path.normalize(`${__dirname}/${htmlRootDir}/${url}`) })
        }
    }, 
    error => console.error(error) 
) 
// ...

htmlRootDir 및/λ˜λŠ” indexFile λ₯Ό μ˜ˆμƒλŒ€λ‘œ λ°”κΎΈλ©΄ λ©λ‹ˆλ‹€.
_Linuxμ—μ„œ ν…ŒμŠ€νŠΈλ¨_

@Myrga 제 ν•˜λ£¨λ₯Ό

@Myrga κΈ€μŽ„, μ΄λŸ¬ν•œ 것듀을 ν•˜λ“œ μ½”λ”©ν•˜λŠ” λŒ€μ‹  "homepage": "./" package.json μ„€μ •ν–ˆμ„ κ²ƒμž…λ‹ˆλ‹€.

@Myrga κΈ€μŽ„, μ΄λŸ¬ν•œ 것듀을 ν•˜λ“œ μ½”λ”©ν•˜λŠ” λŒ€μ‹  "homepage": "./" package.json μ„€μ •ν–ˆμ„ κ²ƒμž…λ‹ˆλ‹€.

@defusioner μ£Όμ„Έμš”, 이것에 λŒ€ν•œ λ¬Έμ„œκ°€ μžˆμŠ΅λ‹ˆκΉŒ?

@leodutra 흠 , λ‚˜λŠ” react-craλ₯Ό μ‚¬μš©ν•˜κ³  있으며 μ΄λŸ¬ν•œ ꡬ성을 생성할 수 μžˆμŠ΅λ‹ˆλ‹€. https://create-react-app.dev/docs/deployment#building -for-relative-paths

@defusioner 흠, λ§Žμ€ 것을 μ„€λͺ…ν•©λ‹ˆλ‹€.
이것은 μ „μž μˆ˜μ€€μ΄ μ•„λ‹Œ 것 κ°™μœΌλ©° λ°˜μ‘ μ•±μš© ν™ˆνŽ˜μ΄μ§€μ— 더 κ°€κΉμŠ΅λ‹ˆλ‹€. μ—¬κΈ°μ„œ 이것은 λͺ¨λ“  μƒλŒ€ λ˜λŠ” 루트 링크의 κΈ°λ³Έ 루트λ₯Ό λŒ€μ²΄ν•©λ‹ˆλ‹€.

제 κ²½μš°μ—λŠ” Vue.js dist λ˜λŠ” raw electron을 μ‚¬μš©ν•˜λ©΄ μ•„λ§ˆλ„ μž‘λ™ν•˜μ§€ μ•Šμ„ κ²ƒμž…λ‹ˆλ‹€.

λ‚˜λŠ”μ΄ νŒ¨ν‚€μ§€ μ ‘κ·Ό 방식을 κ³ λ €ν•΄μ•Όν•œλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€ ... package.json의 electronBasePath 와 같이

win.loadFile('index.html') 은(λŠ”) λ˜₯ κ°™μ•„μš”! electron-builder λ₯Ό μ‚¬μš©ν•˜μ—¬ EXE 파일둜 μ»΄νŒŒμΌν•œ ν›„. 항상 DevTools failed to load SourceMap: Could not load content for file:///C:/User..../resources/app.asar/bootstrap.min.css.map λ©λ‹ˆλ‹€.

κ·ΈλŸ¬λ‚˜ win.loadURL() λŠ” 잘 μž‘λ™ν•©λ‹ˆλ‹€.

λ‚˜λŠ” 이것이 λ‚΄κ°€ ν•΄κ²°ν•  수 μ—†λŠ” λ²„κ·ΈλΌλŠ” 것을 μ•Œμ•„λ‚΄κΈ° μœ„ν•΄ 8μ‹œκ°„μ„ λ³΄λƒˆλ‹€.

지도 νŒŒμΌμ„ μ‹€μ œλ‘œ κ°€μ Έμ˜€κΈ° λ•Œλ¬Έμ— 이 버그가 μ€‘μš”ν•˜μ§€ μ•Šλ‹€λŠ” 것을 κΉ¨λ‹¬μ•˜μŠ΅λ‹ˆλ‹€.

λ‚˜μ—κ²Œ μ‹€μ œ λ²„κ·ΈλŠ” alert() 둜 인해 λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. https://stackoverflow.com/questions/56805920/cant-edit-input-text-field-after-window-alert

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰