forge: Couldn't find preset "env" relative to directory
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project follows, as appropriate.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Please describe your issue:
I have read through https://github.com/electron-userland/electron-forge/issues/154 and am having a duplicate of that issue. It seems that it’s necessary to do some configuration of a .babelrc
somewhere but I don’t grok where or what to do.
I also made a posting in the electron
section of https://discuss.atom.io/c/electron without getting a response.
I followed the directions on the home page of the electron-forge project to set up my Electron application for electron-forge. It is an editor application, and one thing it must do is require
packages that are located in a different directory hierarchy.
That is, it is for editing a project which includes a Configuration object defined in a Node.js module, and there is a package.json in that directory, along with a node_modules directory, and it is required for the editor to load packages from that node_modules directory.
The project directory doesn’t require any Babel anything, and therefore doesn’t have a .babelrc or anything else related.
Launching my editor I get this (with DEBUG output)
$ DEBUG=electron-forge:* npm start
> ae@1.0.0 start /Users/david/akasharender/ae
> electron-forge start
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Checking your system +0ms
electron-forge:lifecycle Process Succeeded: Checking your system +1s
electron-forge:runtime-config setting key: verbose to value: false +0ms
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Locating Application +0ms
electron-forge:project-resolver searching for project in: /Users/david/akasharender/ae +0ms
electron-forge:project-resolver electron-forge compatible package.json found in /Users/david/akasharender/ae/package.json +8ms
electron-forge:lifecycle Process Succeeded: Locating Application +10ms
electron-forge:lifecycle Process Started: Preparing native dependencies +2ms
electron-forge:lifecycle Process Succeeded: Preparing native dependencies +513ms
electron-forge:hook could not find hook: generateAssets +0ms
electron-forge:lifecycle Process Started: Launching Application +8ms
electron-forge:lifecycle Process Succeeded: Launching Application +5ms
[ '/Users/david/akasharender/ae/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron',
'.' ]
App threw an error during load
Error: Couldn't find preset "env" relative to directory "/Users/david/ws/techsparx.com"
at /Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/david/akasharender/ae/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at BabelCompiler.compileSync (/Users/david/akasharender/ae/node_modules/electron-compilers/lib/js/babel.js:81:26)
The directory /Users/david/ws/techsparx.com
is the project directory, and it contains the stuff required to build the techsparx.com website. The editor code is in /Users/david/akasharender/ae
and when I run npm start
the shell’s PWD is in that directory.
During application startup it does this sequence of events:
// See https://discuss.atom.io/t/how-to-make-electron-prebuilt-respect-node-path/21757/8
const configjs = "/Users/david/ws/techsparx.com/config.js";
const configdirname = path.join(path.dirname(configjs), 'node_modules');
require('module').globalPaths.push(configdirname);
const config = require(configjs);
The purpose of this is so that other code in the application can require('akasharender')
(the tool used to build the website). The akasharender
modules are in /Users/david/ws/techsparx.com/node_modules
hence that directory needs to be on NODE_PATH.
I did try in the project directory to do:
$ npm install babel-preset-env
$ npm install babel-preset-react
At first I just installed babel-preset-env
but then it complained it couldn’t find babel-preset-react
. Once both are installed the application starts correctly.
What command line arguments are you passing?
electron-forge start
What does your config.forge
data in package.json
look like?
"config": {
"forge": {
"make_targets": {
"win32": [
"squirrel"
],
"darwin": [
"zip"
],
"linux": [
"deb",
"rpm"
]
},
"electronPackagerConfig": {
"packageManager": "yarn"
},
"electronWinstallerConfig": {
"name": "ae"
},
"electronInstallerDebian": {},
"electronInstallerRedhat": {},
"github_repository": {
"owner": "",
"name": ""
},
"windowsStoreConfig": {
"packageName": "",
"name": "ae"
}
}
},
Please provide either a failing minimal testcase (with a link to the code) or detailed steps to
reproduce your problem. Using electron-forge init
is a good starting point, if that is not the
source of your problem.
$ electron-forge init foo
✔ Checking your system
✔ Initializing Project Directory
✔ Initializing Git Repository
✔ Copying Starter Files
✔ Initializing NPM Module
✔ Installing NPM Dependencies
$ cd foo/
$ ls
node_modules package.json src yarn.lock
$ vi src/index.js
In index.js
I added the following code
const path = require('path');
const util = require('util');
// See https://discuss.atom.io/t/how-to-make-electron-prebuilt-respect-node-path/21757/8
const configjs = "/Users/david/akasharender/a-e/config.js";
const configdirname = path.join(path.dirname(configjs), 'node_modules');
require('module').globalPaths.push(configdirname);
console.log(util.inspect(process.argv));
const config = require(configjs);
You will need to do the following prep work:
$ git clone https://github.com/akashacms/akashacms-example.git
$ cd akashacms-example
$ npm install
Then adjust the path I used above to match where you put the akashacms-example
directory.
Then you run npm start
– I get the following
$ npm start
> foo@1.0.0 start /Users/david/akasharender/foo
> electron-forge start
✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies
✔ Launching Application
Warning, the following targets are using a decimal version:
electron: 1.7
We recommend using a string for minor/patch versions to avoid numbers like 6.10
getting parsed as 6.1, which can lead to unexpected behavior.
[ '/Users/david/akasharender/foo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron',
'.' ]
App threw an error during load
Error: Couldn't find preset "env" relative to directory "/Users/david/akasharender/a-e"
at /Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/david/akasharender/foo/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at BabelCompiler.compileSync (/Users/david/akasharender/foo/node_modules/electron-compilers/lib/js/babel.js:81:26)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (8 by maintainers)
This actually reminded me of a similar issue we had several months ago that was redirected to
babel-present-env
to solve. You might find your solution in there.https://github.com/babel/babel-preset-env/issues/186
Why? As I said above, if that module is installed in the project directory then yes things work. But why should I have to do that? It makes no sense to an akasharender-based project to install that module because akasharender doesn’t rely on any babel anything. Installing a babel plugin there is an intrusion. I’m sorry, but as I see it this is an incorrect requirement imposed by … I’m not sure what is imposing it actually. But it’s just not right.
I’m really disturbed that this bug report was arbitrarily closed when the issue is nowhere near being addressed. This is a bug in something …