For context, I'm working through the example on page 37 of "Programming Phoenix" PDF section "Creating the Project". In order to reproduce this issue, I performed the following:
$ mix phoenix.new rumbl
Fetch and install dependencies? [Yn] y
* running npm install && node node_modules/brunch/bin/brunch build * running mix deps.get
We are all set! Run your Phoenix application:
$ cd rumbl
$ mix ecto.create
$ mix phoenix.server
Error
[info] Running Rumbl.Endpoint with Cowboy on http://localhost:4000
16 Dec 16:39:59 - error: Compiling of 'web/static/js/app.js' failed. Couldn't find preset "es2015" relative to directory "web/static/js" ; Compiling of 'web/static/js/socket.js' failed. Couldn't find preset "es2015" relative to directory "web/static/js" ; Compiling of 'deps/phoenix/web/static/js/phoenix.js' failed. Couldn't find preset "es2015" relative to directory "deps/phoenix/web/static/js" ; Compiling of 'deps/phoenix_html/web/static/js/phoenix_html.js' failed. Couldn't find preset "es2015" relative to directory "deps/phoenix_html/web/static/js"
You just need to install the babel es2015 preset.
https://www.npmjs.com/package/babel-preset-es2015
npm install --save-dev babel-preset-es2015
babel-preset-s2015 fixed an issue I had, but then I blew away my ~/.npm dir with rm -rf ~/.npm. Then I deleted my rm -rf node_modules in the phoenix project and $ npm install. And it worked without having the preset (node stuff). Give that a shot first.
@chrismccord @bryansray The following option worked for me being that I wasn't ready to pull the trigger with rm -rf ~/.npm:
$ npm install --save-dev babel-preset-s2015
Will babel-preset-s2015 NPM package be added to a future release of the Phoenix app creation process or is this something that will get sorted as part of the babel-brunch package?
Will babel-preset-s2015 NPM package be added to a future release of the Phoenix app creation process or is this something that will get sorted as part of the babel-brunch package?
I don't believe there is anything for us to add. Like I said, I had to do this on one project, but not another. When I blew away my ~/.npm directory I no longer needed babel-preset on _any_ project. Please give this a shot and report back:
package.jsonrm -rf ~/.npmcd my_apprm -rf node_modules/npm install@chrismccord For step 2, one can also use the following command:
$ npm cache clean
I'm up and operational without the preset.
Glad to hear it, but bizarre nonetheless. I'm sure we'll be pointing folks to the npm cache clean solution often :)
Actually you need to have node 5.x , (5.1.0 ? )
Before i was running 4.1.2 and could not fix the problem unless I added babel-preset-es2015 by hand
After updating to 5.1.0, removing the node_modules dir and running npm install again, everything was fine.
Leaving this open as I'm sure we'll get folks running into it. It does appear node v5 is now required, but it's not immediately clear why. In any case, node v5 and npm cache clean is the solution. Thanks for verifying!
Leaving this open as I'm sure we'll get folks running into it.
I'm one of them and upgrading from node v4 to v5 indeed fixes the problem.
The official guide (which I was following along) mentions you need node >= 0.5.0 (http://www.phoenixframework.org/docs/installation#section-node-js-0-5-0-). Is this meant to be >= 5.0?
yes, sorry, will fix. Thanks!
Thanks for fixing it (that was quick!). And no worries, the guides have been great so far.
paging @paulmillr hoping he can shed some light on this. Anything we're missing here around babel-brunch issues with node < 0.5?
No ideas. Let's investigate this.
(Edited to be _really_ clear about what needs done)
npm to version 3.Xrm your node_modules directorynpm installnode problem, but an npm problemIt looks less about node >= 5.0 and more about npm >= 3.
npm 3 installs (by default) dependencies flat rather than deep. Due to this, when brunch runs and uses babel-brunch, node finds es2015 in the node_modules directory just as if you had installed it by hand. You can see the output differences of the directory structure below.
The npm team decided to do this for two reasons, AFAIK:
npm without the dreaded "your file path is too long" error that crept up for them.If someone runs sudo npm install npm -g (or however they do package management) then npm will update to its "current" version of 3.5.2.
.
โโโ node_modules
โโโ babel-brunch
โโโ brunch
.
โโโ node_modules
โโโ accepts
โโโ acorn
โโโ amdefine
โโโ ansi-color
โโโ ansi-green
โโโ ansi-regex
โโโ ansi-styles
โโโ ansi-wrap
โโโ anymatch
โโโ anysort
โโโ array-flatten
โโโ array-unique
โโโ arr-diff
โโโ arr-flatten
โโโ arrify
โโโ ast-types
โโโ async-each
โโโ babel-brunch
โโโ babel-code-frame
โโโ babel-core
โโโ babel-generator
โโโ babel-helper-call-delegate
โโโ babel-helper-define-map
โโโ babel-helper-function-name
โโโ babel-helper-get-function-arity
โโโ babel-helper-hoist-variables
โโโ babel-helper-optimise-call-expression
โโโ babel-helper-regex
โโโ babel-helper-replace-supers
โโโ babel-helpers
โโโ babel-messages
โโโ babel-plugin-check-es2015-constants
โโโ babel-plugin-syntax-async-functions
โโโ babel-plugin-transform-es2015-arrow-functions
โโโ babel-plugin-transform-es2015-block-scoped-functions
โโโ babel-plugin-transform-es2015-block-scoping
โโโ babel-plugin-transform-es2015-classes
โโโ babel-plugin-transform-es2015-computed-properties
โโโ babel-plugin-transform-es2015-destructuring
โโโ babel-plugin-transform-es2015-for-of
โโโ babel-plugin-transform-es2015-function-name
โโโ babel-plugin-transform-es2015-literals
โโโ babel-plugin-transform-es2015-modules-commonjs
โโโ babel-plugin-transform-es2015-object-super
โโโ babel-plugin-transform-es2015-parameters
โโโ babel-plugin-transform-es2015-shorthand-properties
โโโ babel-plugin-transform-es2015-spread
โโโ babel-plugin-transform-es2015-sticky-regex
โโโ babel-plugin-transform-es2015-template-literals
โโโ babel-plugin-transform-es2015-typeof-symbol
โโโ babel-plugin-transform-es2015-unicode-regex
โโโ babel-plugin-transform-regenerator
โโโ babel-plugin-transform-strict-mode
โโโ babel-preset-es2015
โโโ babel-register
โโโ babel-runtime
โโโ babel-template
โโโ babel-traverse
โโโ babel-types
โโโ babylon
โโโ balanced-match
โโโ batch
โโโ binary-extensions
โโโ brace-expansion
โโโ braces
โโโ browser-resolve
โโโ brunch
โโโ
โโโ truncated because it's really long...
โโโ
โโโ utils-merge
โโโ vary
โโโ wrap
@realistschuckle does this mean we can close the issue and point folks to this solution?
@paulmillr it feels like so. We are keeping this open in any case to help folks find the solution. :)
This doesn't seem to be working for me. I'm on mac 10.11.2.
โ hello_phoenix node -v
v5.1.1
โ hello_phoenix npm cache clean
โ hello_phoenix rm -rf node_modules
โ hello_phoenix npm install
npm WARN package.json @ No license field.
โ hello_phoenix mix phoenix.server
[info] Running HelloPhoenix.Endpoint with Cowboy on http://localhost:4000
19 Dec 22:46:57 - error: Compiling of 'web/static/js/app.js' failed. Couldn't find preset "es2015" relative to directory "web/static/js" ; Compiling of 'web/static/js/socket.js' failed. Couldn't find preset "es2015" relative to directory "web/static/js" ; Compiling of 'deps/phoenix_html/web/static/js/phoenix_html.js' failed. Couldn't find preset "es2015" relative to directory "deps/phoenix_html/web/static/js" ; Compiling of 'deps/phoenix/web/static/js/phoenix.js' failed. Couldn't find preset "es2015" relative to directory "deps/phoenix/web/static/js"
@Inconditus what is your npm version?
Seems like homebrew has node 5.1.1, but npm 2.14. Uninstalling node from homebrew and downloading it from the official nodejs website fixed the problem.
Homebrew here has installed node 5.1.1 and npm 3.3.12. With those versions installed, blowing away node_modules, npm cache clean, etc. has fixed the problem :)
@Inconditus homebrew uses the official node distributions from node.js which contain both node and npm, together. Here's the formula for it: node.rb. Your machine may have had some different installations of node which may have caused the node executable to come from one package and npm from another. I'd really recommend not losing faith in brew and continue to use it. (I have no affiliation with them, blah, blah, blah.)
@paulmillr @josevalim Is there anything else I can do to make this better for a brighter tomorrow?
I had this issue initially on my local machine but followed this answer on SO and overcame it. I've run into the problem again with running on Heroku. I've included node_version=5.3.0 in my phoenix_static_buildpack.config file.
This updates the version of node to 5.3. Once it's updated, how do I go about removing the node modules and clearing the cache/resetting the remote environment on Heroku?
edit: A crude workaround to get it working on Heroku - destroy the app and remake it. All works as intended when using the correct version of Node from the start.
I'm able to repro this using npm 3.5.2 and node 5.3.0. I also blew away my ~/.npm and node_modules directory without any luck.
@danschultz, can you give me a little more information like your OS, top-level contents of your node_modules directory, and maybe your brunch config?
@realistschuckle here you go:
OS: Mac OS 10.11.1
NPM: 3.5.2
Node: 5.3.0
node_modules, brunch config: https://gist.github.com/danschultz/915444062b9c5663f934
Update
Also, not sure if it matters, but I'm using a umbrella Mix project.
@realistschuckle it seems my issue may be related to using an umbrella project. I created a new Phoenix app outside my umbrella project and the assets compile fine.
Ah, it may be the case. I will investigate. Can you confirm your mix.exs
also has a deps_path configuration?
_Josรฉ Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D_
@josevalim yes it does:
defmodule PhoenixDemo.Mixfile do
use Mix.Project
def project do
[app: :phoenix_demo,
version: "0.0.1",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.0",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases,
deps: deps]
end
...
end
I have tried an umbrella projects and it worked running from both root and inside the dependency. So I don't think it is something related to config, just npm still acting weird.
My apologies, @danschultz. I have had no success in reproducing your problem in normal or umbrella projects. If you'd like to talk more freely on the matter, feel free to contact me directly at [email protected]. I should be in my office after 10am PT just hacking on my own Phoenix project. When we find a solution, we can come back and post it for the community.
Any update on this? I believe I'm having the same issue. I'm on Windows 10, Elixir 1.1.1, Phoenix 1.1.1, Node 5.3.0, and NPM 3.5.3. I'm trying to build an umbrella application consisting of 3 applications: the public website, an admin backend, and an application with an Ecto.Repo, models, and migrations that the admin backend and public website will use (Aside: Is that a good way to keep the public website and admin backend separated? Just learning Elixir/Phoenix so there may be a better way to do it). These are the steps I took that produced the issue.
$ mix new app --umbrella
$ cd app/apps
$ mix phoenix.new admin --module App.Backend
And here is the error shown when running mix phoenix.server in the umbrella application and when creating the Phoenix app admin.
28 Dec 16:45:04 - error: Compiling of '..\..\deps\phoenix_html\web\static\js\phoenix_html.js' failed. Couldn't find preset "es2015" relative to directory "..\\..\\deps\\phoenix_html\\web\\static\\js" ; Compiling of '..\..\deps\phoenix\web\static\js\phoenix.js' failed. Couldn't find preset "es2015" relative to directory "..\\..\\deps\\phoenix\\web\\static\\js"
@chncdcksn I tried your steps on OS X and couldn't get the same error. Now, booting up a Windows 10 VM to try to reproduce. Thanks for the steps! Just to confirm:
cd down into the apps directorymix phoenix.server and get a sad, sad error(Installing Erlang/Elixir, right now, into VM. This may take a while...:)
[19 minutes later]
All installed. Going to start looking at this, now.
@realistschuckle you are my hero for taking on digging deeper into the windows issues :heart_eyes:
@chrismccord It's really no problem. Thanks for Programming Phoenix. I've enjoyed watching the book mature over the last five beta releases.
@realistschuckle Yup, those are the steps. With mix phoenix.server being run in the directory of the umbrella app, not the Phoenix app (that's probably what you mean, but I'm new to OTP so I figured I'd be explicit).
I know how we can fix the es2015 issue. I'll submit the necessary patches to babel-brunch today
@chncdcksn Totally reproduced and trying to figure it out, now. I think what's happening is that the working directory of the include gets changed to the relative path ../../deps/phoenix_html/web/static/js in babel which, then, kills the node search path. I'm trying to run down if its babel or brunch or brunch using babel.
@paulmillr Thanks! Really great!
The quickfix for now:
# Execute
npm i -s babel-preset-es2015 babel-preset-react
# Add this to your brunch-config.coffee
plugins:
babel:
presets: ['es2015', 'react']
@realistschuckle Did your tests also produce the other error I had (you must restart your server after changing the following configuration files)? Or should I move that to other issue?
@paulmillr Thanks!
@paulmillr I tried your workaround, but now I'm getting an error when running brunch build:
dan$ node node_modules/brunch/bin/brunch build
/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:1747
throw err;
^
SyntaxError: Unexpected token (2:10)
at Parser.pp.raise (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:1745:13)
at Parser.pp.unexpected (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2264:8)
at Parser.pp.semicolon (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2243:59)
at Parser.pp.parseExpressionStatement (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2677:8)
at Parser.pp.parseStatement (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2462:160)
at Parser.pp.parseBlock (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2692:21)
at Parser.pp.parseStatement (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2443:19)
at Parser.pp.parseTopLevel (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:2379:21)
at Object.parse (/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:101:12)
at parse (/Users/dan/Development/elixir/brunch_demo/node_modules/detective/index.js:9:18)
at Function.exports.find (/Users/dan/Development/elixir/brunch_demo/node_modules/detective/index.js:44:15)
at module.exports (/Users/dan/Development/elixir/brunch_demo/node_modules/detective/index.js:23:20)
at /Users/dan/Development/elixir/brunch_demo/node_modules/deppack/index.js:83:12
at tryToString (fs.js:414:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:401:12)
Is there another dependency that I need to update? Here's my current package.json:
{
"repository": {},
"dependencies": {
"babel-brunch": "^6.0.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"brunch": "^2.0.0",
"clean-css-brunch": ">= 1.0 < 1.8",
"css-brunch": ">= 1.0 < 1.8",
"javascript-brunch": ">= 1.0 < 1.8",
"uglify-js-brunch": ">= 1.0 < 1.8"
}
}
@danschultz try npm: enabled: false in your config
@paulmillr setting npm enabled to false reverts back to the original error
error: Compiling of '../../deps/phoenix/web/static/js/phoenix.js' failed. Couldn't find preset "es2015" relative to directory "../../deps/phoenix/web/static/js" ; Compiling of '../../deps/phoenix_html/web/static/js/phoenix_html.js' failed. Couldn't find preset "es2015" relative to directory "../../deps/phoenix_html/web/static/js"
@danschultz any ideas on how I could get to the point of error with the default phoenix app?
@paulmillr I've only been able to repro with an umbrella app.
Environment:
OS: Mac OSX 10.11.1
Node: 5.3.0 (installed via brew)
NPM: 3.5.2 (upgraded via sudo npm install npm -g)
Elixir/Mix: 1.1.1
Phoenix: 1.1.1
Steps to repro:
mix new umbrella_app --umbrellacd umbrella_app/appsmix phoenix.new hello_phoenixcd hello_phoenixmix phoenix.server[info] Running HelloPhoenix.Endpoint with Cowboy using http on port 4000
29 Dec 20:14:41 - error: Compiling of '../../deps/phoenix/web/static/js/phoenix.js' failed. Couldn't find preset "es2015" relative to directory "../../deps/phoenix/web/static/js" ; Compiling of '../../deps/phoenix_html/web/static/js/phoenix_html.js' failed. Couldn't find preset "es2015" relative to directory "../../deps/phoenix_html/web/static/js"
Steps to repro + your suggested workaround:
npm i --save babel-preset-es2015 babel-preset-reactbrunch-config.js:
plugins: {
babel: {
presets: ['es2015', 'react'],
ignore: [/web\/static\/vendor/]
}
}
mix phoenix.server[info] Running HelloPhoenix.Endpoint with Cowboy using http on port 4000
/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:1747
throw err;
^
SyntaxError: Unexpected token (2:10)
at Parser.pp.raise (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:1745:13)
at Parser.pp.unexpected (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2264:8)
at Parser.pp.semicolon (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2243:59)
at Parser.pp.parseExpressionStatement (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2677:8)
at Parser.pp.parseStatement (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2462:160)
at Parser.pp.parseBlock (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2692:21)
at Parser.pp.parseStatement (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2443:19)
at Parser.pp.parseTopLevel (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:2379:21)
at Object.parse (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/acorn/dist/acorn.js:101:12)
at parse (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/detective/index.js:9:18)
at Function.exports.find (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/detective/index.js:44:15)
at module.exports (/Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/detective/index.js:23:20)
at /Users/dan/Development/elixir/umbrella_app/apps/hello_phoenix/node_modules/deppack/index.js:83:12
at tryToString (fs.js:414:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:401:12)
Setting npm: false in brunch-config.js results in the original error.
Hope this helps!
This is happening with umbrella apps, I confirm. This is, however, probably a separate issue.
The temporary workaround I found, is to generate the app outside of umbrella's main directory and move it manually inside umbrella app.
Ok, just to confirm: who can reproduce the umbrella issue given @danschultz instructions? I certainly cannot.
I can.
Node: v5.3.0
NPM: 3.5.2
Phoenix: 1.1.1
I'll check with phoenix master and report back.
I can too.
Node: v5.3.0
NPM: 3.5.2
Phoenix: 1.1.1
OS: Fedora 23
Elixir: 1.1.1
Erlang: 18
Generating app inside umbrella: errors like in this topic
Generating app outside umbrella and moving it inside: works like a charm
An and I'm on Linux too. Maybe it's Mac vs Linux issue.
Yes, I can confirm this is still an issue on Phoenix master.
Ok. I was able to reproduce it. The issue is that, because phoenix and phoenix_html are in the parent directories, brunch/babel is unable to find the preset for those dependencies.
Here is the directory structure:
your_app
node_modules
brunch-config.js
package.json
deps
phoenix_html
web/static/js
phoenix
web/static/js
Because we are inside "/apps/your_app", importing a file defined at "/deps/phoenix_html/web/static/js", brunch/babel is looking for the es2015 preset at "/node_modules", however, the node modules is inside "/apps/your_app" which is from where we effectively run brunch.
@paulmillr is this something we can solve inside brunch? Can we tell it to always use the node_modules directory from the current working directory and not attempt to lookup one at the root of the files being imported? I will create a small project that reproduces the issue in a second.
To clarify, I believe this is the bug because if I copy the "/apps/your_app/node_modules" to "/node_modules", everything works.
Ok, here we go. To reproduce the bug:
git clone https://github.com/josevalim/brunch-sample.gitcd brunch-sample/apps/hello_phoenixnpm installnode_modules/brunch/bin/brunch buildThe reason why it happens is because we are inside "apps/your_app" requiring files from "../../deps/phoenix". For some reason, npm/brunch/babel is expecting to find a node_modules at "../../node_modules" instead of using the one inside "apps/your_app".
@paulmillr is there anything I can do to help this further? Should I open up an issue on brunch issues tracker? Thanks for all the help.
Interesting. Let me check this
Fixed in babel-brunch from github: https://github.com/babel/babel-brunch/pull/19. Just waiting for folks to accept the pull request & release 6.0.1 now.
We have been passing filename option into babel to preserve filenames in source maps. Babel searches for plugins in a dir relative to the filename: https://phabricator.babeljs.io/T2974
This is expected behaviour. You haven't specified a
filenameso it has no idea where to resolve presets and plugins from so it just uses the cwd.
Well that's pretty fucking stupid. Babel needs another option for "resolving presets and plugins".
@paulmillr I saw that setting sourceRoot is commented out in your PR. Is it not yet supported then?
sourceRoot is something different. I've just tried a few variables and none of them do the required job. Babel needs a new option for that.
Awesome, thanks for clarifying and fixing @paulmillr !
I am getting the following error on node 5.3.0:
error: Compiling of deps/phoenix/web/static/js/phoenix.js failed. deps/phoenix/web/static/js/phoenix.js: Duplicate declaration "channel"
This is my package.json:
{
"repository": {},
"devDependencies": {
"testing": ">=0.2.3"
},
"dependencies": {
"babel-brunch": "^6.0.0",
"brunch": ">= 2.1.0",
"clean-css-brunch": ">= 1.8.0",
"closure-library": "Immortalin/closure-library",
"css-brunch": ">= 1.0 < 1.8",
"javascript-brunch": ">= 1.8.0",
"node_erlastic": ">= 0.0.8",
"uglify-js-brunch": ">= 1.0 < 1.8",
"xmldom": "^0.1.19"
}
}
Still waiting for the PR to be accepted: https://github.com/babel/babel-brunch/pull/19
Updating NPM from 2.X to 3.X fixed the issue for me.
Elixir: 1.2.0
Node: 4.2.4
NPM: 3.5.2 (before update was 2.14.12)
Phoenix: 1.1.1
Updating from Node 4.2.6 to Node 5.5.0 solved the problem for me (NVM)
@danschultz i'm running into the same issue as you, did you even find a way to make it work ?
For people who have this error:
dan$ node node_modules/brunch/bin/brunch build
/Users/dan/Development/elixir/brunch_demo/node_modules/acorn/dist/acorn.js:1747
throw err;
^
SyntaxError: Unexpected token (2:10)
If your phoenix version is before 1.1.2 you'll need to upgrade to >= 1.1.2.
Make sure to update your deps and you can use this guide https://gist.github.com/chrismccord/d5bc5f8e38c8f76cad33 to upgrade.
Updating npm solved this issue for me as well. I assumed I was on the latest having done:
rumbl git:(master) โ brew upgrade npm
Error: node 5.6.0 already installed
When running npm -v though, I noticed I was on a 2.x version. I ran
rumbl git:(master) โ npm update npm -g
And was then updated to npm 3.7.3 which seemed to resolve this for me :)
I seem to be having a related issue:
14 Feb 14:01:26 - error: Compiling of web/static/js/socket.js failed. Couldn't find preset "stage-0" relative to directory "/Users/mos8580/dev" ; Compiling of web/static/js/app.js failed. Couldn't find preset "stage-0" relative to directory "/Users/mos8580/dev"
It's stage-0 instead of es2015 but it looks like the same issue. The project was created at ~/dev/hello_phoenix.
Node and npm installed with "brew install node".
OS: Mac OS X 10.11.3
Node: 5.6.0
Npm: 3.6.0
Phoenix: 1.1.4
I updated npm with "npm update -g npm" to 3.7.3, but no luck.
I tried in a Debian VM with same node et npm versions (5.6.0, 3.6.0) and didn't get the problem. Any ideas welcome.
Can you reproduce it in a fresh project? Often the issue is cached npm files, so if you nuke node_modules and clean the cache, you should be golden.
It is on a fresh project, I'm actually following the guide for phoenix, this is my first experience with it. I've even recreated the whole thing several times. I'll gladly provide more info if it can help.
I still have this issue with an umbrella project. Notably, I'm experiencing this after migrating a standalone phoenix app into an umbrella project.
Edit: I've found that if I copy the node_modules directory into the project root before running ../../node_modules/brunch/bin/brunch build --production, it does indeed compile.
Edit (2): After speaking with @chrismccord over IRC, the issue in my case was that I'd not gone through the upgrade motions between 1.1.1 and 1.1.2: https://gist.github.com/chrismccord/d5bc5f8e38c8f76cad33
node - v5.5.0
npm - v3.7.3
Phoenix - v1.1.4
My way of fixing the problem was putting a .babelrc in my apps root directory
{ "presets": ["es2015"] }
lazy copy paste (while in your pheonix apps root):
echo '{ "presets":["es2015"] }' > .babelrc
My guess would be to include this by default, as long as babel is being used.- but i'd like to see if this helps other people first.
I confirm this fixes the problem for me. Completely forgot about .babelrc ...
Thanks!
Apparently there has been a .babelrc in the master branch since 2270aaf21bd02c6a6a1022820564efb605a97655 - I'm going to try installing phoenix on a fresh machine and report back. I'm not sure if phoenix new includes this .babelrc by default, so the fix might be to make sure phoenix.new includes this file (if its skipping dotfiles)
The babelrc is strictly for phoenix-core development, not for generated projects. The .babelrc should not be required for any projects on latest node/npm/brunch versions
Just to document my workflow - i've done this twice with two fresh machines:
node - v5.5.0
npm - v3.7.3
Phoenix - v1.1.4
MacOS - v 10.11.2
brew install elixir
mix local.hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
mix phoenix.new test
cd test
mix phoenix.server
[info] Running Bacon.Endpoint with Cowboy using http on port 4000
24 Feb 19:57:14 - error: Compiling of web/static/js/app.js failed. Couldn't find preset "es2015" relative to directory "/Users/username" ; Compiling of web/static/js/socket.js failed. Couldn't find preset "es2015" relative to directory "/Users/username"
Confirmed, adding a .babelrc to root does indeed fix this issue for both machines.
I've also tried:
Update/FIX:
I noticed I had a .babelrc in my home directory. What is happening is that babel crawls up directories until root and looks for a .babelrc file and uses that file... (similar to how eslint functions) but when it finds the file, it tries using node_modules in the directory it found the babelrc, so it can't find the preset.
Deleting ~/.babelrc fixes the issue for me.
There isn't really any good documentation on the proper use case of .babelrc, but to fix this issue for people who are improperly configured, you can simply tell babel-brunch not to look for a babelrc and it works great. In my opinion its a partially sensible default - but it might be confusing for someone who wants to use a babelrc in this case.
I think the main problem stems from a misconception on how babelrc works, in comparison to the likes of eslintrc, where its permissible to set your global configuration in your home directory.
I had a .babelrc in the parent directory from the phoenix project. Deleting it indeed resolved the issue.
@mos8580 I actually asked you to try making that in the pheonix project directory so that was probably my fault :(
ideally its not having one at all that eventually fixed my issue.
Unless you mean the parent direct above the pheonix directory - ex: I keep my code in ~/Code, so my parent directory would be ~/
I'm at guilt for following a guide somewhere or automatically assuming the .babelrc as a global configuration was a good option as well :(
@Eein To be honest I tried just about everything anyway. I think that behaviour of Babel is a bit sneaky, but that's my bad for not knowing the tooling.
Thank you for for finding the real solution =]
I have the exact same issue as described by Eein 28 days ago.
Make sure you're on Brunch 2.5, node 4+ and npm 3+.
you can also do the following
babel-preset-es2015 as a requirement in your package.jsonbrunch-config.json like so plugins: { babel: { presets: ['es2015'], ... } }npm install mix phoenix.server and you should be good to goCould we close the issue? I think that's been long resolved since be we don't have new comments @chrismccord
<3 <3 <3
Just had the issue, and this was the quick fix: npm install --save-dev babel-preset-es2015
Thanks!
Adding "babel-preset-es2015": "^6.9.0", or similar to the devDependencies in package.json is still required it seems, had to do this with a fresh install last night (Phoenix 1.2.0)
@mikekreuzer Which versions of node/npm are you using?
I haven't encountered this with new projects for months.
Node's 6.3.0, npm was 3.10.3, 3.10.5 now, using nvm if that's significant. Node weirdness is why I'm using Phoenix. :-)
The dependency should be provided by babel-brunch.
Can you run npm list babel-preset-es2015 on your repository that doesn't work?
If you can push your repository with this issue, that would also be helpful.
Working after adding it manually:
โโโฌ [email protected]
โ โโโ [email protected]
โโโ [email protected]
And also working out of the box now on another fresh project:
โโโฌ [email protected]
โโโ [email protected]
Neither's on a repo, I threw them up to test something unrelated... but it seems to be working for me now too (annoyingly).
The only thing worked for me was running this command on ubuntu: sudo npm install --save-dev babel-preset-es2015
As a late addition.
Deleted node_modules and used the new facebook Yarn tool and got a working result.
Good topic for first use phoenix!
Just wanted to leave a note that I can reproduce the issue with 1.3.0 rc2.
OS : MacOS 10.12.5
Node : 8.0.0
NPM : 5.0.1
Erlang : OTP 19
Elixir : 1.4.4
STR:
Actual result :
Brunch build fails on es2015 linking.
Expected result:
A phoenix app is ready to be developed.
Workaround:
On the 'Fetch and install dependencies? [Yn]' step, select N and run mix deps.get separately.
It should be noted that mix phoenix.new works without issue.
Managed to build a development app stored inside phoenix directory created with mix phx.new $app_name --dev by:
cd phoenix
npm install babel-preset-es2015
Most helpful comment
You just need to install the babel es2015 preset.
https://www.npmjs.com/package/babel-preset-es2015