webpack linux resolve path - linux

I am using webpack with react, I have Index.js file in Administrator folder
I can import without includes Index in path in Mac and windows
import Admin from '../components/Administrator/'
but when I call webpack in Linux ,it can't resolve file, but after I change it to
import Admin from '../components/Administrator/Index'
and it works.
I would like to fix this issue without adding Index in path as our colleges use Mac and Windows. if they forgot to add that, the code will broken in production, Does any one know what's the reason?

Related

how to fix "Error: Cannot find module '/home/container/index.js'", I've tried everything

So the host that I use for my discord bot died so I downloaded all the code and tried hosting it on my PC. But I get the following error.
Error: Cannot find module '/home/container/index.js
I've tried everything I can:
updated nodejs
reinstalled all my packages
Changed package.json
How can I fix this?
Cannot find module means you are trying to run non-existent file.
Ensure there is index.js in your working directory. If not,
Use cd to go to the directory where it is (usually it's src near the package.json)
Run node ./index.js
Many time people have just the problem of command line to run file,
as windows and linux have
different syntax to run .js file
i.e. node ./index.js for linux
and node .\index.js for windows

Why I'm getting Error [ERR_MODULE_NOT_FOUND]: Cannot find module when running the server

I'm doing a startup server. Basically It has initial setup with express and nodemon dependencies. Unfortunately, I'm getting ERR_MODULE_NOT_FOUND when running yarn dev or npm run dev
Here is the code and file structure I have.
The issue is a missing file extension. The import needs to look like this:
import { sampleExport } from "../config/env.js";
// ^^^
import doesn't use the same algorithm that require used. Instead, it works according to the ECMAScript Modules specification, which requires a definite extension.
This is also explained in the node.js docs for ECMAScript modules:
A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes (e.g. './startup/index.js') must also be fully specified.
This behavior matches how import behaves in browser environments, assuming a typically configured server.
You need to add .js extension
index.js:
import { SampleExport } from "../path/file.js"
In my opinion, it is better to use .env files together with some npm package or even a json file.

NodeJS relative import using `#` - Module is not installed in WebStorm

I am working on a project created by others in Node.JS.
Noticed a pattern I've never used before.
All the inside imports are used with #.
ex: import Config from '#config/config';
Where config is a file inside /src/config/config.js.
Now, it's working flowlessly but WebStorm keeps complain about Module is not installed and suggest me to Install #config/config as dev dependency.
The real issue behind it is that WebStorm isn't able to autocomplete or help me in any other way regard those imports.
And how do I configure WebStorm to understand this?
Thanks!

How to Import nodes modules in react native

hope you're doing well.
I'm new at react native and i'm stuck with a problem while trying to import a node module.
I need to create an app that will get orders from the API of a Wordpress Website with WooCommerce.
I first created a project with the command create-react-native-app picking then npm install. It's creating a structure like this in the project folder named picking:
node_modules
App.js
app.json
App.test.js
etc....
Then I installed the package woocommerce-api with npm install woocommerce-api --save (https://www.npmjs.com/package/woocommerce-api). This package allow me to do request to the WooCommerce API easier.
I want to not put the config to the WooCommerce API in the App.js, so I created a folder src and a folder woocommerce with a file api.js (should I write it with the first letter in uppercase ?) in it and I added import Api from 'picking/src/woocommerce/api'; in my App.js.
So now the structure is
node_modules
src
-- woocommerce
-- api.js
App.js
app.json
App.test.js
etc....
The problem is that I can't achieve to import the WooCommerceAPI module from woocommerce-api, no matter what I set in path to get the module.
There is the file api.js at the moment :
import WooCommerceAPI from '../../woocommerce-api';
var Api = new WooCommerceAPI({
url: 'http://localhost/mysite',
consumerKey: 'ck_xxxxxxxxxxxxxxxxxxxxxxxxxx',
consumerSecret: 'cs_xxxxxxxxxxxxxxxxxxxxxxxxxxx',
wp_api: true,
version: '/wc/v2',
queryStringAuth: true
});
export default Api;
And I get the error :
Unable to resolve module '../../woocommerce-api' from etc ...
I can't find what is the problem and why this is not working. If you could help me on this, it would be very nice.
Have a nice day everyone :)
EDIT: I changed the line for the import to import WooCommerceAPI from 'woocommerce-api'; and I got a new error : Metro Bundler has encountered an internal error, please check your terminal error output for more details, but there is nothing in the terminal except Failed building JavaScript bundle.
EDIT2: I downgrade node from 9.4 to 8.0.0 and restart the project. I got the same error but in the terminal i now get this in yellow/orange : Problem checking node_modules dependencies: Unexpected end of JSON input
Okay, so I find a workaround. In fact, the import is working. For some reason that i don't know, this is the npm package that is not working and make the app crash.
So I removed the package woocommerce-api and I create a file in src/woocommerce called woocommerce-api.js, then I copied the content of this https://github.com/minhcasi/react-native-woocommerce/blob/master/WooCommerceAPI.js that is the same as the one in the npm package and I pasted it in my woocommerce-api.js. I import it in my api.jsfile and "voilĂ " !
Seems to work fine.
As you install woocommerce-api in your project there is no need to place the location like ../../woocommerce-api.
just change ../../woocommerce-api to woocommerce-api and your project should work.

trying to load electron.BrowserWindow into an aurelia app

I'm trying to import electron into my aurelia app but I can not, if I use import it does not find de folder where electron is, if I change the import to use the exact folder then it seems to begin to load but then fails to find drip, which I installed but electron seems to search for it in the wrong folder to :(. So I tried to use require to load it but it give's me a 'require is not a function', that is when I find your comment where you propose to import require so I installed npm:require but when I try to imorte it aurelia cant either.
So my question is: can someone help me to load electron into my aurelia app?
thanks!.

Resources