首页 > 解决方案 > 没有这样的文件或目录,打开'package.json'

问题描述

我是一名尝试使用与 Webpack 捆绑的 Electron(以前称为 Atom)和 Angular 2 的初学者。在我尝试构建包之前,一切都运行良好。

尝试运行 exe,我得到了臭名昭著的错误:

Uncaught Error: ENOENT: no such file or directory, open 'E:\Electron\careersarthi\release-builds\careersarthi-win32-ia325\package.json'
    at Object.fs.openSync (fs.js:584:18)
    at Object.module.(anonymous function) [as openSync] (ELECTRON_ASAR.js:173:20)
    at Object.fs.readFileSync (fs.js:491:33)
    at Object.fs.readFileSync (ELECTRON_ASAR.js:505:29)
    at Object.__WEBPACK_AMD_DEFINE_FACTORY__ (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/app.js:37177:19)
    at __webpack_require__ (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/polyfills.js:53:30)
    at Object.c (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/app.js:129829:10)
    at __webpack_require__ (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/polyfills.js:53:30)
    at Object.c (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/app.js:83525:38)
    at __webpack_require__ (file:///E:/Electron/careersarthi/release-builds/careersarthi-win32-ia325/resources/app.asar/src/app/dist/polyfills.js:53:30)

我试过重新安装电子和 node_modules

这是我的 webpack.config.js:

// @joaogarin

/*
 * Helper: root(), and rootDir() are defined at the bottom
 */
const webpack = require('webpack');
const helpers = require('./helpers');
const path = require('path');

var CopyWebpackPlugin = require('copy-webpack-plugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');

/*
 * Config
 */
var config = {
    // for faster builds use 'eval'
    devtool: 'source-map',
    // cache: false,

    // our angular app
    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'app': './src/app/app',
    },

    // Config for our build files
    output: {
        path: helpers.root('src/app/dist'),
        filename: '[name].js',
        sourceMapFilename: '[name].map',
        chunkFilename: '[id].chunk.js'
    },
    /*
    * Options affecting the resolving of modules.
    *
    * See: http://webpack.github.io/docs/configuration.html#resolve
    */
    resolve: {
        /*
         * An array of extensions that should be used to resolve modules.
         *
         * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
         */
        extensions: ['.ts', '.js', '.json', '.css', '.html'],

        // An array of directory names to be resolved to the current directory
        modules: [helpers.root('src'), 'node_modules'],

    },
    /*
    * Options affecting the resolving of modules.
    *
    * See: http://webpack.github.io/docs/configuration.html#resolve
    */
    module: {
        rules: [
            // Support for .ts files.
            {
                test: /\.ts$/,
                loaders: ['awesome-typescript-loader', 'angular2-template-loader'],
                exclude: [/\.(spec|e2e)\.ts$/]
            },

            // Support for *.json files.
            {
                test: /\.json$/,
                loader: 'json-loader'
            },
            {
                test: /\.scss$/,
                exclude: /node_modules/,
                loaders: ['raw-loader', 'sass-loader'] // sass-loader not scss-loader
            },

            // support for .html antd .css as raw text
            {
                test: /\.html$/,
                loader: 'raw-loader',
                exclude: [helpers.root('app/index.html')]
            },

            // support for fonts
            {
                test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
                loader: 'file-loader?name=dist/[name]-[hash].[ext]'
            },

            // support for svg icons
            {
                test: /\.svg/,
                loader: 'svg-url-loader'
            }
        ]
    },
    plugins: [

        // Plugin: CommonsChunkPlugin
        // Description: Shares common code between the pages.
        // It identifies common modules and put them into a commons chunk.
        //
        // See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
        // See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
        new webpack.optimize.CommonsChunkPlugin({ name: ['vendor', 'polyfills'], minChunks: Infinity }),
        // Plugin: CopyWebpackPlugin
        // Description: Copy files and directories in webpack.
        //
        // Copies project static assets.
        //
        // See: https://www.npmjs.com/package/copy-webpack-plugin
        new CopyWebpackPlugin([{ from: 'src/assets', to: 'assets' }]),
        /**
       * Plugin LoaderOptionsPlugin (experimental)
       *
       * See: https://gist.github.com/sokra/27b24881210b56bbaff7
       */
        new LoaderOptionsPlugin({
            debug: true,
            options: {
                /**
                 * Static analysis linter for TypeScript advanced options configuration
                 * Description: An extensible linter for the TypeScript language.
                 *
                 * See: https://github.com/wbuchwalter/tslint-loader
                 */
                tslint: {
                    emitErrors: false,
                    failOnHint: false,
                    resourcePath: 'src'
                },
            }
        }),
    ],
    // we need this due to problems with es6-shim
    node: {
        global: true,
        progress: false,
        crypto: 'empty',
        module: false,
        clearImmediate: false,
        setImmediate: false
    }
};

/**
 * Target Electron
 */
config.target = 'electron-renderer';
module.exports = config;

这是我的 package.json:

{
  "name": "careersarthi",
  "version": "1.0.0",
  "description": "careersarthi",
  "main": "main.js",
  "scripts": {
    "watch": "npm run watch:dev",
    "watch:dev": "webpack --watch --progress --profile",
    "build": "npm run build:dev",
    "build:dev": "webpack --progress --profile",
    "package": "node package.js",
    "package-all": "npm run package -- --all",
    "electron": "electron .",
    "webpack-test": "webpack --config webpack.test.js --progress --profile",
    "test": "karma start",
    "package-win32": "electron-packager . --overwrite --asar=false --platform=win32 --arch=ia32 --icon=./logos/icon.ico  --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=CareerSarthi",
    "package-linux": "electron-packager . --overwrite --asar=false --platform=linux --arch=x64 --out=release-builds --version=1.4.3 --version-string.CompanyName=CE --version-string.ProductName=Career Sarthi --version-string.ProductVersion=1.0",
    "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=./images/icon.icns --prune=true --out=release-builds",
    "deb64": "electron-installer-debian --src ./release-builds/Sarthi-linux-x64/ --dest release-builds --arch amd64"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/joaogarin/angular2-electron.git"
  },
  "author": "Abc",
  "license": "ABC",
  "bugs": {
    "url": "http://www.example.com"
  },
  "homepage": "http://www.example.com",
  "dependencies": {
    "@angular/animations": "^4.4.7",
    "@angular/cdk": "^5.1.1",
    "@angular/common": "^4.4.7",
    "@angular/compiler": "^4.4.7",
    "@angular/core": "^4.4.7",
    "@angular/forms": "^4.4.7",
    "@angular/http": "^4.4.7",
    "@angular/material": "^2.0.0-beta.12",
    "@angular/platform-browser": "^4.4.7",
    "@angular/platform-browser-dynamic": "^4.4.7",
    "@angular/platform-server": "^4.4.7",
    "@angular/router": "^4.4.7",
    "@ngrx/core": "^1.2.0",
    "@ngrx/store": "^2.2.1",
    "@types/chart.js": "^2.7.22",
    "@types/jspdf": "^1.1.31",
    "angular-node-fs": "0.0.3",
    "angular2-infinite-scroll": "^0.3.5",
    "angular2-masonry": "^0.4.0",
    "angular2-spinner": "^1.0.10",
    "async": "^0.9.0",
    "aws-sdk": "^2.259.1",
    "base64-img": "^1.0.4",
    "bcrypt-pbkdf": "^1.0.1",
    "chart.js": "^2.7.2",
    "copy-webpack-plugin": "^4.5.1",
    "core-js": "^2.5.7",
    "ecc-jsbn": "^0.1.1",
    "electron": "^2.0.2",
    "electron-db": "^0.8.1",
    "electron-settings": "^3.2.0",
    "graceful-fs": "^4.1.11",
    "hammerjs": "^2.0.8",
    "jsbn": "^1.1.0",
    "jspdf": "^1.4.1",
    "ng-pdf-make": "0.0.2",
    "ng2-charts": "^1.6.0",
    "ng2-pdf-viewer": "^2.0.3",
    "ngx-scroll-event": "^1.0.8",
    "node-machine-id": "^1.1.10",
    "pdfkit": "^0.8.3",
    "rxjs": "^5.5.11",
    "tweetnacl": "^1.0.0",
    "webpack-target-electron-renderer": "^0.4.0",
    "xml2js": "^0.4.19",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@types/hammerjs": "^2.0.33",
    "@types/jasmine": "^2.8.8",
    "@types/js-base64": "^2.3.1",
    "@types/moment-timezone": "^0.2.32",
    "@types/node": "^8.10.20",
    "@types/source-map": "^0.5.0",
    "@types/uglify-js": "^2.6.31",
    "@types/webpack": "^3.8.12",
    "angular2-template-loader": "^0.6.0",
    "awesome-typescript-loader": "^3.5.0",
    "chai": "^2.0.0",
    "codelyzer": "^3.0.0",
    "css-loader": "^0.28.11",
    "devtron": "^1.4.0",
    "electron-packager": "^10.1.2",
    "es6-promise-loader": "^1.0.1",
    "extract-text-webpack-plugin": "^2.0.0",
    "file-loader": "^0.11.0",
    "imports-loader": "^0.7.0",
    "istanbul-instrumenter-loader": "^2.0.0",
    "jasmine-core": "^2.99.1",
    "json-loader": "^0.5.4",
    "karma": "^2.0.3",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.1.2",
    "karma-jasmine": "^1.1.2",
    "karma-mocha-reporter": "^2.0.0",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-remap-coverage": "^0.1.4",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^3.0.0",
    "node-sass": "^4.9.0",
    "phantomjs-polyfill": "0.0.2",
    "phantomjs-prebuilt": "^2.1.7",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "remap-istanbul": "^0.9.0",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.7",
    "source-map-loader": "^0.2.1",
    "style-loader": "^0.18.1",
    "svg-url-loader": "^2.3.2",
    "ts-helpers": "^1.1.1",
    "tsconfig-lint": "^0.12.0",
    "tslint": "^5.10.0",
    "tslint-loader": "^3.6.0",
    "typescript": "~2.3.1",
    "url-loader": "^1.0.1",
    "webpack": "2.3.3",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-dev-server": "2.5.0"
  },
  "engines": {
    "node": ">= 4.2.1 <= 6",
    "npm": ">= 5.2"
  }
}

标签: electronelectron-packager

解决方案


推荐阅读