-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Can't find module within modulesDirectories #2119
Comments
It is correct. |
So it works not exactly like node_modules does? I can't understand the logic. |
|
Ok, got it. My idea was to achieve following resolution order: |
yep, that's the best solution with webpack 1. with webpack 2 modules: [
"package_modules",
"/path/to/app",
"node_modules"
] |
Wow 👍 |
Playing with webpack 2 (2.1.0-beta.4), I implemented files structure as in topic and
After some debugging, I found the rule: everything from Please explain what's going on here. |
Actually, same happens even with the most simple configuration.
src/index.js: console.log(require("constants")); src/constants.js: module.exports = { foo: "foo" }; webpack.config.js: module.exports = {
entry: "index.js",
output: {
filename: "build.js"
},
resolve: {
modules: [
__dirname + "/src"
]
}
};
|
add the |
How |
That is not related to the first problem you posted. So I suggest installing json-loader to get past this |
@eisisig @sokra Once again: in this example webpack is configured to search for modules only in
Should I post this as separate issue? |
@jeron-diovis I have encountered exactly the same problem. It's weird that webpack tries to import My webpack config:
When i try to import something like that in my src/app/index.js
that couses the error, but works when i use relative path:
|
Can you try against current webpack 2 rc? It handles JSON now. |
@bebraw same issue here with |
@valerybugakov Any chance for a repository to study to confirm the issue? |
I can create one later today. But maybe you know a way to ignore this module in the client code? |
@valerybugakov Ok. There are things like |
@bebraw Short version of what I have right now: import { ENTITIES } from 'constants'; it's transpiled into var _constants = __webpack_require__("./node_modules/constants-browserify/constants.json"); And webpack config: // some imports and env stuff here...
module.exports = {
stats,
devServer: {
stats,
hotOnly: true,
contentBase: path.join(__dirname, 'dev')
},
devtool: dev ? 'eval' : false,
entry: [
path.join(__dirname, '../index.web.js')
],
output: {
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules/react-native-vector-icons'),
path.resolve(__dirname, '../node_modules/react-native-drawer'),
path.resolve(__dirname, '../node_modules/react-native-popup-dialog'),
path.resolve(__dirname, '../node_modules/react-native-modalbox'),
path.resolve(__dirname, '../node_modules/react-native-flip-card'),
path.resolve(__dirname, '../node_modules/react-native-snap-carousel'),
],
options: { cacheDirectory: true },
},
{
test: /\.(gif|jpe?g|png|svg|tff)$/,
loader: 'url-loader',
options: { name: '[name].[hash:16].[ext]' }
},
{
test: /\.ttf$/,
loader: 'file-loader', // or directly file-loader
include: [
path.resolve(__dirname, '../node_modules/react-native-vector-icons'),
path.resolve(__dirname, '../src/assets/icons'),
]
},
{
test: /\.worker.js$/,
loader: 'worker-loader',
options: { inline: true }
},
{
test: /\.glsl$/,
loader: 'shader-loader'
},
],
},
resolve: {
extensions: ['.js', '.web.js'],
alias: {
'react-native': 'react-native-web',
},
modules: [
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules'),
],
},
plugins,
}; |
module: {
noParse: /constants-browserify/,
}, Didn't help :( |
@valerybugakov Why |
@bebraw actually there're more destructured variables |
@valerybugakov Ok, basically this feels like a JSON and ES6 module syntax specific problem. Could you open a separate issue with a little example we can run? You can also try the old |
@bebraw Ok, let me try |
@bebraw no, same result: const constants = require('constants')
// transpiled into
var constants = __webpack_require__("./node_modules/constants-browserify/constants.json"); |
@valerybugakov Ah... I understand better now. You basically want to inline the result ( |
Lol, I found a workaround, but will open an issue with example later. alias: {
'react-native': 'react-native-web',
'constants': path.resolve(__dirname, '../src/constants'),
}, |
@bebraw I think export const ENTITIES = ['some', 'entities', 'here', ...]
export const STICKY_CATEGORIES = [...] |
@valerybugakov Yeah, |
@bebraw yeah, will do that. Thanks for helping out :) |
What is the status of this issue? |
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
webpack config:
Option
resolve.root
is not defined.Files tree:
lib/index:
export const foo = "foo"
;my_package/package_modules/lib/index:
export const bar = "bar"
;my_package/file_in_package:
my_package/subfolder/file_in_subfolder:
In console I have:
Is it correct? I expected that it will be
{ bar: "bar" }
in both cases.Changing import path to
lib/index
does not help.The text was updated successfully, but these errors were encountered: