schovi / webpack-chrome-extension

Moved and redesigned into https://github.com/schovi/create-chrome-extension
MIT License
167 stars 27 forks source link

Failed to write file #31

Open cladder opened 6 years ago

cladder commented 6 years ago

Env: Win10 Err Message:

Making injector 'popup/index.js'
[16:45:24] 'manifest' errored after 33 ms
[16:45:24] Error: ENOENT: no such file or directory, open 'E:\web\extensions\qwt\build\popup\index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.writeFileSync (fs.js:1327:33)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/lib/script.js:38:8)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/lib/html.js:39:3)
    at process (E:/web/extensions/qwt/dev-env/manifest/processor/action.js:6:16)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/action.js:21:3)
    at E:/web/extensions/qwt/dev-env/manifest/index.js:66:9
    at Array.forEach (native)
    at Manifest.processManifest (E:/web/extensions/qwt/dev-env/manifest/index.js:64:16)

how to solve this problem??

cladder commented 6 years ago

Well, I found the problem... in file dev-env/manifest/processor/lib/script.js line 37

const injectorScript = makeInjector(scriptName);
    const injectorFilepath = path.join(buildPath, scriptName);
    const injectorPath = Remove.file(injectorFilepath)
    // problem goes here,injectorPath => ''???
    mkdirp.sync(injectorPath)
    // if I change to mkdirp.sync(path.dirname(injectorFilepath)) then it works.
    fs.writeFileSync(injectorFilepath, injectorScript, {encoding: 'utf8'})

    log.done()
cladder commented 6 years ago

应该是Remove.file的问题

var injectorFilePath = 'E:\web\extensions\qwt\build\popup\index.js';
Remove.file(injectorFilepath);     // ''

image 在win上路径会是\而不是/,这就是为什么会出问题了。dev-env/remove.js

export function file(filepath) {
   // not works on win32 because the path seperator is '\' but not '/'
  return filepath.split("/").slice(0,-1).join("/")
}
cladder commented 6 years ago

why not use path.dirname ? in file dev-env/remove.js I change it to

import path from 'path';
...
export const file = path.dirname;

and it works on my win10 laptop.