I am using VSCode on Windows. I have set up a boilerplate ElectronJS app and want to use React for the UI. I have main.js, index.html, preload.js and renderer.js.
I have installed these and other packages (like babel) via npm. I see react and other packages in node_modules/ however I can't figure out how to get React imported.
Here is my project structure
node_modules/
.gitignore
index.html
main.js
preload.js
renderer.js
In my renderer.js file I have done as I see other people demonstrate:
import React from 'react';
import ReactDOM from 'react-dom';
In the Electron app's developer console I see: Uncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".
So I have switched to:
import React from './node_modules/react'
(In the dev console: Failed to load resource: net::ERR_FILE_NOT_FOUND)
For all of these options (separately!):
import React from './node_modules/react/index.js'
import React from './node_modules/react/umd/react.development.js';
import React from import React from './node_modules/react/cjs/react.development.js';
(because it looks like that file reads a Node environment variable to export up either the Dev or Prod version, so it seemed like it might be my entry point) I get "The requested module ... does not provide an export named 'default'.
This will work:
import * as React from 'react';
import * as ReactDOM from 'react-dom';