electron-react-boilerplate / electron-react-boilerplate/examples

Native module "fswin" not working on Windows (typescript boilerplate)

Open
#30 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
200
Forks
37
PR merge metrics
No merged PRs in 30d

Description

## Prerequisites

- [x] Using yarn
- [x] Using node 10.x
- [x] Using an up-to-date `master` branch
- [x] Using latest version of devtools. See [wiki for howto update](https://github.com/electron-react-boilerplate/electron-react-boilerplate/wiki/DevTools)
- [ ] Link to stacktrace in a Gist (for bugs)
- [ ] For issue in production release, devtools output of `DEBUG_PROD=true yarn build && yarn start`
- [x] Tried solutions mentioned in [#400](https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/400)

## Expected Behavior

I can add and use the native module [`fswin`](https://github.com/xxoo/node-fswin) when using the typescript boilerplate.

## Current Behavior

I just don't get the module `fswin` to work with the typescript example of ERB; the app does not load and the following error in `ELECTRON_ASAR.js:160` is written into the DevTools console:

```
Uncaught Error: The specified module could not be found.
\\?\D:\development\workspace\test-ts-fswin-error\node_modules\fswin\electron\x64\fswin.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:722)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
at Module.load (internal/modules/cjs/loader.js:602)
at tryModuleLoad (internal/modules/cjs/loader.js:541)
at Function.Module._load (internal/modules/cjs/loader.js:533)
at Module.require (internal/modules/cjs/loader.js:640)
at require (internal/modules/cjs/helpers.js:20)
at Object. (D:\development\workspace\test-ts-fswin-error\node_modules\fswin\index.js:3)
at Object. (D:\development\workspace\test-ts-fswin-error\node_modules\fswin\index.js:7)
```

The `fswin.node` file exist in the folder reported by the error. As I read in various github issues, such an error can occur even if the .node file exists if the native module did not get compiled correctly, due to DLLs not present on the working machine.

But since I can use the module with pure NodeJS, and also with **the normal JS version of ERB** (tested with [ae89980](https://github.com/electron-react-boilerplate/electron-react-boilerplate/commit/ae8998075a4b46d0fa11520bbaf80ddcb4f8df1f)), I am sure that the module got compiled correctly.

It seems to me like the module not getting _bundled_ correctly when using your typescript boilerplate example.

Since I could not figure out the problem, I would be glad if you could help me!

*Further notes*:
- I tried both the traditional `require` and also the ES6 `import` syntax, without success.
- The error also occurs when using `UPGRADE_EXTENSIONS=1 yarn dev`, or `yarn package` and starting the packaged app.

## Steps to Reproduce (for bugs)

1. `git clone https://github.com/electron-react-boilerplate/examples`

2. `cd examples/examples/typescript`

3. `yarn`

4. `yarn add fswin`

5. for testing purposes, add the following lines to index.tsx:

```javascript
...
import { configureStore, history } from './store/configureStore';
import './app.global.css';

const fswin = require('fswin'); // ADDED
console.log(fswin); // ADDED

const store = configureStore();
...
```

6. `yarn dev` --> Error is shown in the DevTools console, counter app is not loaded

![erb-typescript-fswin-error](https://user-images.githubusercontent.com/13141109/53102265-99b2ab80-352b-11e9-8ea1-640680f5e374.png)

## Context

I am working with the file system on windows and want to know if files are hidden or system-files. Since both node and electron don't expose APIs for that, I have to use a native module, and `fswin` seems to be a good choice for that.
As you can see with the steps to reproduce, no changes in the boilerplate were made.

## Your Environment

- Node version : `10.15.1`
- Yarn version : `1.13.0`
- Version or Branch used : [90294db](https://github.com/electron-react-boilerplate/examples/commit/90294db0655bb32d24cb454d5ba96e1a8a3ffa00)
- Operating System and version : Windows 10 64-bit

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.