Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support] Cannot determine webpack context. (Are you executing webpack from a directory outside of your project?). #82

Closed
Aerendir opened this issue Jul 6, 2017 · 5 comments

Comments

@Aerendir
Copy link

Aerendir commented Jul 6, 2017

I've just installed Encore to test it and start using it in my projects (great great work!!! Really, thank you!).

I'm immediately having an issue.

When trying to run ./node_modules/.bin/encore dev I receive the exception:

Cannot determine webpack context. (Are you executing webpack from a directory outside of your project?). Try passing the --context option.

I've simply followed the instructions in the official documentation about the first example and the result is this exception.

My project is structured like so:

my-app-root-folder
- app
- bin
- nome_modules
- src
- tests
- var
- vendor
- web
...
composer.json
composer.lock
webpack.config.js

So, basically, I have the classical structure of a Symfony 3.3 project, plus some folders related to JS.

Can anyone help me solve this problem?

This is the very first time I approach a more sophisticated solution to manage css and javascript assets.

Unitl now I've done all putting those files in src/AppBundle/Resources/public/ so I'm not very experienced with this new flow.

Thank you!

I've opened also a question on StackOverflow.

@weaverryan
Copy link
Member

Hey @Aerendir!

Awesome, welcome :). Does your project have a package.json file? It's not mentioned in your file list, and we actually look for this to find the root of your project. That's the first place to look. We might need to improve the error message if that's the case. Though, if it is, how did you install everything and avoid creating the package.json file?

Cheers!

@Aerendir
Copy link
Author

Aerendir commented Jul 6, 2017

Hi @weaverryan , thank you :)

Anyway, no, currently there is no package.json file.

Looking at it, it there isn't.

I've not created it as the documentation states that it should be created automatically:

This command creates (or modifies) a package.json file and downloads dependencies into a node_modules/ directory.

But I've used npm instead of yarn: maybe this is the reason why the package.json were not created?

Anyway, what should have I to put into it if I want to create it manually?

@weaverryan
Copy link
Member

But I've used npm instead of yarn: maybe this is the reason why the package.json were not created?

Yep, that's likely the problem :). I'd recommend using yarn, especially if you're starting new with this stuff (so that you will not have any surprises). But if you want to use npm, you should:

  • Run (at the root of your project) npm init. This will generate a basic package.json for you. The questions it asks are generally not important - you can just use the default value for most of them.

  • Re-run all the npm install commands that you used to install Encore, but make sure you add a --save-dev flag on the end. Unless you're using the latest version of npm (npm 5), you must add --save-dev when you install things with npm, otherwise it will install them but NOT update the package.json file, which is a bit silly :).

Cheers!

@Aerendir
Copy link
Author

Aerendir commented Jul 6, 2017

Ok, I've created the package.json file and now all works well.

But the documentation should be fixed as now it tells that the file is created automatically while it isn't.

Also the exception could be more clear...

In my package.json I've put this:

{
    "version": "0.0.1",
    "name": "My-App",
    "private": true,
    "devDependencies": {
        "@symfony/webpack-encore": "~0.9",
        "bootstrap": "~3"
    }
}

@Aerendir Aerendir closed this as completed Jul 6, 2017
@Aerendir
Copy link
Author

Aerendir commented Jul 6, 2017

And just for completeness, after running npm init:

{
  "name": "my-app",
  "version": "0.0.1",
  "description": "My app description",
  "main": "webpack.config.js",
  "directories": {
    "doc": "docs",
    "test": "tests"
  },
  "dependencies": {
    "bootstrap": "^3.3.7"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://git@bitbucket.org/Aerendir/my-app.git"
  },
  "author": "Aerendir",
  "license": "UNLICENSED",
  "homepage": "https://bitbucket.org/Aerendir/my-app#readme"
}

Again, really thank thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants