{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/3269","repository_url":"https://api.github.com/repos/webpack/webpack","labels_url":"https://api.github.com/repos/webpack/webpack/issues/3269/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/3269/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/3269/events","html_url":"https://github.com/webpack/webpack/issues/3269","id":188564923,"number":3269,"title":"webpack looks in the wrong dir with enough `../../../` if \"context\" is used","user":{"login":"Pomax","id":177243,"avatar_url":"https://avatars.githubusercontent.com/u/177243?v=3","gravatar_id":"","url":"https://api.github.com/users/Pomax","html_url":"https://github.com/Pomax","followers_url":"https://api.github.com/users/Pomax/followers","following_url":"https://api.github.com/users/Pomax/following{/other_user}","gists_url":"https://api.github.com/users/Pomax/gists{/gist_id}","starred_url":"https://api.github.com/users/Pomax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pomax/subscriptions","organizations_url":"https://api.github.com/users/Pomax/orgs","repos_url":"https://api.github.com/users/Pomax/repos","events_url":"https://api.github.com/users/Pomax/events{/privacy}","received_events_url":"https://api.github.com/users/Pomax/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-10T17:07:11Z","updated_at":"2016-11-14T18:20:09Z","closed_at":null,"body":"This is a pretty weird bug, but it's reproducible for me (at least on Windows 10 with Node 6.9).\r\n\r\nWhen using a webpack config that uses a `\"context\"` to indicate its default require context path, trying to load modules with relative pathing anywhere inside the file tree that has the context path as root works fine. For example:\r\n\r\n- `\"context\": context: '${__dirname}/app'` (where ' are backticks but github syntax won't let me do that)\r\n- file `./app/js/test.js` importing `\"../dependency.js\"`\r\n\r\nthis works, and a bundle in which `test.js` will import the code from `./app/dependency.js` gets built. Perfect. The following also works fine:\r\n\r\n- `\"context\": context: '${__dirname}/app'`\r\n- file `./app/js/test.js` importing `\"./config/dependency.js\"`\r\n\r\nthis works, and a bundle in which `test.js` will import the code from `./app/js/config/dependency.js` gets built. Again, perfect.\r\n\r\nThis, however, breaks super hard:\r\n\r\n- `\"context\": context: '${__dirname}/app'`\r\n- file `./app/js/test.js` importing `\"../../config/dependency.js\"`\r\n\r\nInstead of creating a bundle in which `test.js` will import the code from `config/dependency.js` relative to the dir one higher than `app`, it suddenly looks *two* higher, as if it now suddenly resolves the path relative to the `context` path, not the path of the script that is doing the require/import.\r\n\r\nAs PoC create a test file structure as follows:\r\n\r\n```\r\n ./\r\n ./BASE\r\n ./BASE/app\r\n ./BASE/app/js\r\n```\r\n\r\nand create a file `./BASE/package.json`\r\n```\r\n{\r\n  \"name\": \"BASE\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"\",\r\n  \"main\": \"webpack.config.js\",\r\n  \"scripts\": {\r\n    \"test\": \"webpack --config webpack.config.js --display-error-details\"\r\n  },\r\n  \"keywords\": [],\r\n  \"author\": \"\",\r\n  \"license\": \"ISC\",\r\n  \"dependencies\": {\r\n    \"webpack\": \"^1.13.3\",\r\n    \"babel-core\": \"^6.18.2\",\r\n    \"babel-loader\": \"^6.2.7\",\r\n    \"babel-preset-es2015\": \"^6.18.0\"\r\n  }\r\n}\r\n```\r\n\r\nAnd create a `./BASE/webpack.config.js` with content:\r\n\r\n```\r\nvar webpack = require(`webpack`);\r\n\r\nmodule.exports = {\r\n  context: `${__dirname}/app`,\r\n  entry: {\r\n    javascript: `./browser.js`\r\n  },\r\n  output: {\r\n    filename: `/js/browser.js`,\r\n    path: `${__dirname}/dist`\r\n  },\r\n  module: {\r\n    loaders: [\r\n      {\r\n        test: /\\.js$/,\r\n        exclude: /node_modules/,\r\n        loader: `babel`,\r\n        query: {\r\n          presets: [`es2015`]\r\n        }\r\n      }\r\n    ]\r\n  }\r\n};\r\n```\r\n\r\nNote the `context` variable being set to the \"app\" directory here using an absolute path.\r\n\r\nAlso create the entry file `./BASE/app/browser.js`:\r\n\r\n```\r\nimport Thing from \"./js/test.js\"\r\n```\r\n\r\nAnd create a similarly tiny file `./BASE/app/js/test.js`:\r\n\r\n```\r\nimport willfail from \"../config/willfail.js\"\r\nimport willfailtoo from \"../../config/willfailtoo.js\"\r\n```\r\n\r\nDone - running `npm test` will now demonstrate this problem through its error logging. The test.js is trying to perform two imports, from dirs that *should* be one step apart. However, the logs clearly show a two step separation, with `../../` doing what appears to be entirely the wrong thing.\r\n\r\nFirst error, with what seems the correct path based on `test.js` doing the relative import:\r\n```\r\nERROR in ./js/test.js\r\nModule not found: Error: Cannot resolve 'file' or 'directory' ../config/willfail.js in C:\\...\\Git projects\\temp\\BASE/app\\js\r\nresolve file\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.webpack.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.web.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.json doesn't exist\r\nresolve directory\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js doesn't exist (directory default file)\r\n  C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js\\package.json doesn't exist (directory description file)\r\n[C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js]\r\n[C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.webpack.js]\r\n[C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.js]\r\n[C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.web.js]\r\n[C:\\...\\Git projects\\temp\\BASE/app\\config\\willfail.js.json]\r\n @ ./js/test.js 3:16-48\r\n```\r\n\r\nSecond error, with what seems the entirely wrong path based on `test.js` doing the relative import:\r\n```\r\nERROR in ./js/test.js\r\nModule not found: Error: Cannot resolve 'file' or 'directory' ../../config/willfailtoo.js in C:\\...\\Git projects\\temp\\BASE/app\\js\r\nresolve file\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js.webpack.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js.web.js doesn't exist\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js.json doesn't exist\r\nresolve directory\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js doesn't exist (directory default file)\r\n  C:\\...\\Git projects\\temp\\config\\willfailtoo.js\\package.json doesn't exist (directory description file)\r\n[C:\\...\\Git projects\\temp\\config\\willfailtoo.js]\r\n[C:\\...\\Git projects\\temp\\config\\willfailtoo.js.webpack.js]\r\n[C:\\...\\Git projects\\temp\\config\\willfailtoo.js.js]\r\n[C:\\...\\Git projects\\temp\\config\\willfailtoo.js.web.js]\r\n[C:\\...\\Git projects\\temp\\config\\willfailtoo.js.json]\r\n @ ./js/test.js 7:19-57\r\n```\r\n\r\nNote that even though we tried to import with `..` and `../..` respectively, the first error is about not finding a file in `temp/BASE/app/`, and the second error is about `temp/`. Somehow, `temp/BASE/` has become inaccessible to webpack, and I'm pretty sure this is a bug in how `../..` is getting interpreted when there is a `context` set."},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/260416550","html_url":"https://github.com/webpack/webpack/issues/3269#issuecomment-260416550","issue_url":"https://api.github.com/repos/webpack/webpack/issues/3269","id":260416550,"user":{"login":"Pomax","id":177243,"avatar_url":"https://avatars.githubusercontent.com/u/177243?v=3","gravatar_id":"","url":"https://api.github.com/users/Pomax","html_url":"https://github.com/Pomax","followers_url":"https://api.github.com/users/Pomax/followers","following_url":"https://api.github.com/users/Pomax/following{/other_user}","gists_url":"https://api.github.com/users/Pomax/gists{/gist_id}","starred_url":"https://api.github.com/users/Pomax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pomax/subscriptions","organizations_url":"https://api.github.com/users/Pomax/orgs","repos_url":"https://api.github.com/users/Pomax/repos","events_url":"https://api.github.com/users/Pomax/events{/privacy}","received_events_url":"https://api.github.com/users/Pomax/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T18:20:09Z","updated_at":"2016-11-14T18:20:09Z","body":"apologies for the delay - I tried running this on windows 10 pro with `path.resolve(__dirname, 'app')` rather than the templated string, but the result is the same: two \"not found\" stack traces that show `BASE` getting skipped over."}}
{"actor":{"display_login":"Pomax"}}