The site loses all functionalities after building it. In develop mode everything works fine, but when I build the website it looks like all scripts are missing. Bootstrap (Carousel DropDowns) are not responding, leflet map and background image not loading and react-multi-carousel do not work. I don't see any errors in the browser console, of course I ran gatsby clean before building. I uploaded the project to netlify. Below I am enclosing the json package:
{
"name": "Website",
"private": true,
"description": "Description",
"version": "0.1.0",
"license": "0BSD",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-brands-svg-icons": "^5.15.3",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/react-fontawesome": "^0.1.14",
"bootstrap": "^4.6.0",
"gatsby": "^3.2.1",
"gatsby-background-image": "^1.5.0",
"gatsby-image": "^3.2.0",
"gatsby-link": "^3.2.0",
"gatsby-plugin-image": "^1.2.0",
"gatsby-plugin-postcss": "^4.2.0",
"gatsby-plugin-react-helmet": "^4.2.0",
"gatsby-plugin-react-leaflet": "^3.0.0",
"gatsby-plugin-recaptcha": "^1.0.5",
"gatsby-plugin-robots-txt": "^1.5.5",
"gatsby-plugin-sass": "^4.2.0",
"gatsby-plugin-sharp": "^3.2.0",
"gatsby-plugin-sitemap": "^3.2.0",
"gatsby-remark-images": "^4.2.0",
"gatsby-source-filesystem": "^3.2.0",
"gatsby-transformer-remark": "^3.2.0",
"gatsby-transformer-sharp": "^3.2.0",
"gbimage-bridge": "^0.1.2",
"leaflet": "^1.7.1",
"node-sass": "^5.0.0",
"postcss": "^8.2.9",
"react": "^17.0.2",
"react-animations": "^1.0.0",
"react-bootstrap": "^1.5.2",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
"react-leaflet": "^3.1.0",
"react-multi-carousel": "^2.6.2",
"react-scripts": "^4.0.3",
"styled-components": "^5.2.3"
},
"devDependencies": {
"http-proxy-middleware": "^1.1.0",
"netlify-lambda": "^2.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1"
}
}
There's not much debug in the question however, to me, it seems that you are using some dependencies outside React's scope, which may potentially block React's hydration process, which may explain the problem described. For example, using Leaflet instead of React's Leaflet or (depending on its implementation) Bootstrap instead of React's Boostrap.
You should be able to change all React-unfriendly modules to React's ones without too much effort and that should fix your problems.
Keep in mind that if your project "work in develop and breaks in build" doesn't mean that your project work or stops working, it just means that is working under certain and specific circumstances. Basically, and summarizing (to avoid extending the answer), gatsby develop uses the browser as an interpreter, where there are, among other things, global objects like window or document. However, gatsby build occurs in the Node server, where at the build time, there are not global objects because there are not even created yet, that the main reason why you may face a different behavior between both scenarios but doesn't mean that the project stopped working magically.
You can read further details in the Overview of Gatsby Build Process.
Another option, linked with blocking React's hydration, is that some component may be blocking that process because of its own behavior. Be careful when using global objects like window or document (or when importing modules that uses it), they use should be always be wrapped inside the following condition, as you can see from the docs:
When referencing window in a React component.
import * as React from "react"
// Check if window is defined (so if in the browser or in node.js).
const isBrowser = typeof window !== "undefined"
export default function MyComponent() {
let loggedIn = false
if (isBrowser) {
window.localstorage.getItem("isLoggedIn") === "true"
}
return <div>Am I logged in? {loggedIn}</div>
}
Or when requiring a module:
// Requiring a function causes an error during builds
// as the code tries to reference window
const module = require("module") // Error
// Wrap the require in check for window
if (typeof window !== `undefined`) {
const module = require("module")
}
The same approach can be done using loadable components as the docs suggests but without providing any piece of code it's impossible to guess what should be its implementation.
I solved the problem by wrapping the leaflet maps in Loadable
import React from 'react';
import Loadable from "#loadable/component"
const LoadableMap = Loadable(() => import("./map.js"))
export default LoadableMap;
Related
I have a working nextjs app and am wanting to add Cypress component tests for my react components.
e2e cypress tests are working without issue, but when trying to implement component tests I'm receiving the error, "Cannot read properties of undefined (reading 'displayName')" when trying to mount a component.
I followed the documentation at https://docs.cypress.io/guides/component-testing/component-framework-configuration#Next-jsn and also accepted the configuration that was generated by the cypress tool when I ran yarn cypress.
My code with component testing issue is at https://gitlab.com/kennyrbr/activ/-/tree/cypress-testing/web
Here is where I'm attempting to mount .
import React from 'react';
import { mount } from '#cypress/react';
import { NavBar } from '../../components/NavBar';
describe('NavBar.cy.ts', () => {
it('playground', () => {
cy.mount(`<NavBar />`);
});
});
My package.json is
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"gen": "graphql-codegen --config codegen.yml",
"cypress": "cypress open"
},
"dependencies": {
"#graphql-codegen/typescript-urql": "^3.6.1",
"#urql/exchange-graphcache": "^4.4.3",
"daisyui": "^2.22.0",
"formik": "^2.2.9",
"graphql": "^16.5.0",
"next": "latest",
"next-urql": "^3.3.3",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-is": "^18.2.0",
"urql": "^2.2.2",
"yup": "^0.32.11"
},
"devDependencies": {
"#cypress/react": "^6.1.1",
"#cypress/webpack-dev-server": "^2.2.0",
"#graphql-codegen/cli": "^2.8.0",
"#graphql-codegen/typescript": "^2.7.1",
"#graphql-codegen/typescript-operations": "^2.5.1",
"#testing-library/cypress": "^8.0.3",
"#types/node": "17.0.35",
"#types/react": "18.0.9",
"#types/react-dom": "18.0.5",
"autoprefixer": "^10.4.7",
"cypress": "^10.6.0",
"html-webpack-plugin": "^5.5.0",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.2",
"typescript": "4.7.2",
"webpack": "^5.74.0",
"webpack-dev-server": "^4.10.0"
}
}
Here's the error which displays after running yarn cypress and choosing component testing for the 'NavBar.cy.ts' test.
N.B., I did add a few dev dependencies because I was receiving a webpack warning early on.
Any help is greatly appreciated.
edit:
I had added an incorrect displayName assignment to some of my components in an attempt to get cypress component testing working - and had forgotten to remove in a previous commit. This wasn't even the issue as displayName couldn't be read from undefined, so I think the issue is that the component/s aren't available to cypress. In any case, it was wrong and I've removed.
The basic problem is the parameter you are passing into cy.mount() isn't being compiled to JSX.
Two things should fix it
take the quotes off the JSX, so it should be cy.mount(<NavBar />);
change the extension of the spec file to NavBar.cy.tsx
It's not really a working nextjs app, you are getting the exact same message from a different component SelectActivType.tsx when you you run the app (outside of the Cypress test).
In terms of the NavBar, the code should be adjusted from this
export const NavBar: React.FC<NavBarProps> = ({}) => {
NavBar.displayName = 'ActivTypes';
const router = useRouter();
return (
...
);
}
to this
export const NavBar: React.FC<NavBarProps> = ({}) => {
const router = useRouter();
return (
...
);
}
// move the offending line outside of the function
NavBar.displayName = 'ActivTypes';
You cannot add a property to a function inside the function definition.
For reference see how to set displayName in a functional component [React].
I am using styled-jsx in my project and I just migrated it to a monorepo structure, and since then I have been having the following problem:
Type '{ children: string; jsx: true; }' is not assignable to type
'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.
Property 'jsx' does not exist on type
'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.ts(2322)
This appears under the jsx attribute every time I use the default tag for style-jsx:
<style jsx>
{`...`}
</style>
I found a closed issue about this subject, and according to this link, this issue can be solved if I manually add the following two lines to interface HTMLAttributes in react/index.d.ts:
jsx?: boolean;
global?: boolean;
This actually solved the problem, but I don't want to manually modify a file from node_modules.
According to this closed issue in vercel, I should be able to fix this by simply running yarn add -D #types/styled-jsx, but this didn't work.
Installing the packages using using npm instead of yarn fixed the problem too, but I don't want to change the package manager I am using. Furthermore, installing this one package with npm and the others with yarn crashed the application.
I thought this could be a hoisting problem related to styled-jsx and yarn workspaces, but adding
"private": true,
"nohoist":["**/styled-jsx","**/styled-jsx/**"]
to my root package.json and to the package.json of the project that uses styled-jsx didn't fix the problem either.
Does any one have a solution to this problem that does not involve manually modifying react/index.d.ts, changing my package manager or abandoning the monorepo structure?
The package.json of the project that uses styled-jsx:
{
"name": "with-typescript",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-check": "tsc",
"lint": "eslint **/**",
"lint:fix": "eslint **/** --fix",
"test": "NODE_ENV=test jest --passWithNoTests --watch",
"test:ci": "NODE_ENV=test jest --passWithNoTests"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.34",
"#fortawesome/free-solid-svg-icons": "^5.15.2",
"#fortawesome/react-fontawesome": "^0.1.14",
"#types/styled-jsx": "^2.2.8",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
"firebase": "^8.2.4",
"firebase-admin": "^9.4.2",
"formidable": "^1.2.2",
"global": "^4.4.0",
"isomorphic-unfetch": "3.0.0",
"jest": "^25.2.1",
"js-cookie": "^2.2.1",
"next": "^10.0.5",
"path": "^0.12.7",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.2.0",
"styled-components": "^5.2.1",
"styled-jsx": "^3.4.1"
},
"devDependencies": {
"#types/formidable": "^1.0.32",
"#types/js-cookie": "^2.2.6",
"#types/node": "^12.12.21",
"#types/react": "^16.9.16",
"#types/react-dom": "^16.9.4",
"#types/react-router-dom": "^5.1.7",
"#types/styled-components": "^5.1.7",
"#types/styled-jsx": "^2.2.8",
"#typescript-eslint/eslint-plugin": "^4.14.0",
"#typescript-eslint/parser": "^4.14.0",
"eslint": "^7.18.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^1.18.2",
"typescript": "3.7.3"
},
"license": "ISC"
}
The package.json of my root folder:
{
"name": "next_shsc",
"version": "1.0.0",
"main": "index.js",
"private":true,
"repository": "https://github.com/agaragon/next_shsc.git",
"author": "aragon <andregaragon#gmail.com>",
"license": "MIT",
"workspaces":{
"packages": [
"packages/*"
]
}
}
This solution fixed the issue for me (after #smeijer at GitHub):
Create a TypeScript Declaration File, named e.g. custom.d.ts:
import 'react';
declare module 'react' {
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> {
jsx?: boolean;
global?: boolean;
}
}
Place it somewhere in the project, for example in the /src/typings folder. It should be picked up by the compiler automatically, but it may possibly depend on the config (?).
If you get eslint error complaining about the import 'react' line, put the following comment above it:
// eslint-disable-next-line react/no-typos`
Installing the #types/styled-jsx package didn't work for me - it's a stub for the types, as styled-jsx includes their own now.
Reading the docs on the styled-jsx github, there's a specific solution for this: https://github.com/vercel/styled-jsx#typescript
Adding a file at the root of my next app named styled-jsx.d.ts and putting this in it worked for me:
/// <reference types="styled-jsx" />
I am using Next 12.1.6 and I had this problem until I installed #types/styled-jsx 3.4.4.
I think it is a better approach.
Using pnpm 7 in a monorepo and Next 12.2.0 I had to install styled-jsx in my app with pnpm add styled-jsx
I have a project based on nextjs. Oddly enough, the HMR is not working properly for my project. Every time I make changes I have to re run the process. I have attached details of my next config and package.json:
next.config:
const withSass = require("#zeit/next-sass");
const withCSS = require("#zeit/next-css");
module.exports = withCSS(
withSass({
webpack(config, options) {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: "url-loader",
options: {
limit: 100000,
},
},
});
return config;
}
})
);
package.json
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "next export"
},
"dependencies": {
"#zeit/next-css": "^1.0.1",
"#zeit/next-sass": "^1.0.1",
"antd": "^3.26.8",
"chartjs": "^0.3.24",
"classnames": "^2.2.6",
"draft-js": "^0.11.4",
"isomorphic-unfetch": "^3.0.0",
"moment": "^2.24.0",
"next": "^9.2.1",
"node-sass": "^4.13.1",
"react": "16.12.0",
"react-dom": "16.12.0",
"react-helmet": "^5.2.1",
"react-markdown": "^4.3.1",
"react-mde": "^8.1.0",
"react-redux": "^7.2.0",
"react-select": "^3.0.8",
"react-slick": "^0.25.2",
"react-toastify": "^5.5.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"showdown": "^1.9.1",
"slick-carousel": "^1.8.1"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-react": "^7.18.3",
"url-loader": "^3.0.0"
}
I have tried removing node_modules and reinstalling again as well, doesnt seem to fix the issue.
Following is my project structure
Got help from #felixmosh. There was issue because of my folders were case was not matching route case. Fixed the issues by changing folder name to route names.
I just solved this problem by deleting folder ".next" and then closing terminal, and run npm run dev again.
Sometimes, when you accidentally name a component starting with a lowercase and then later changes to capital letter, next cache will still consider the older name and won't count it as a normal component.
The easiest solution is to copy the contents of the components, delete the file, and create one with a proper component name.
in my case hot reload didn't work because there was assetsPrefix in my next.config.js. You can remove or change them to "/" in the development mode and everything will be as expected.
For people NOT using modules and using Typescript paths.
For my setup, I just like having general .scss files
So, in my _app.tsx
I add Styles/index.scss
Then, in my index.scss
I add my #import '~Styles/flex.scss'
take note of the ~
this was required for it to work with hot reloading.
Wrt to Next js version 10+ and in addition to Pranay's answer, make sure your routes case matches the case of the folder.
Also, I noticed the component name has to start with the upper case. If your file name is dashboard.jsx, the component name should be Dashboard.
// home/dashboard.js
const Dashboard = () => {
....
}
export default Dashboard
I had to go to package.json remove react and react-dom and re add them with yarn add.
In my case, it wasn't working on Chrome. But it was working on Edge browser. And funny enough... even on a guest chrome window.
So all I had to do was...
Clear the cookies and hard refresh.
Force audit fix worked for me. Don't know the exact reason, might be some conflicts between dependencies.
Steps
1)Run this command in your next project directory.
npm audit fix --force
you need to run npm run dev instead npm run start
So I've been trying to figure this for a while right now and I'm at the end of my rope here.
I'm trying to create a react application that makes simple API calls but I keep getting this error that prevents my lodable component from being rendered.
It comes out as a props.error which I log into chrome's console.log()
In the chrome's console I get:
TypeError: fs.existsSync is not a function
at Object.hasBinary (extensions.js:404)
at module.exports (binding.js:11)
at Object.<anonymous> (index.js:14)
at Object../node_modules/node-sass/lib/index.js (index.js:471)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/components/FeatureCallouts.js (lib sync:9)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/components/template.js (styles.scss?8f6b:45)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
at Object../src/routes/app/routes/tacas/index.js (index.js:1)
at __webpack_require__ (bootstrap:772)
at fn (bootstrap:141)
I think it has something to do with the './node_modules/node-sass/lib/binding.js' file which is:
/*!
* node-sass: lib/binding.js
*/
var errors = require('./errors');
/**
* Require binding
*/
module.exports = function(ext) {
if (!ext.hasBinary(ext.getBinaryPath())) {
if (!ext.isSupportedEnvironment()) {
throw new Error(errors.unsupportedEnvironment());
} else {
throw new Error(errors.missingBinary());
}
}
return require(ext.getBinaryPath());
};
Also in the build CMD terminal, I am also getting this Warning:
./node_modules/node-sass/lib/binding.js
19:9-37 Critical dependency: the request of a dependency is an expression
I've looked at other questions similar to this but none seem to work for me. For instance, I don't have a webpack.config file at all.
Just in case here is my package.json file:
{
"name": "material",
"private": true,
"version": "4.0.0",
"main": "",
"homepage": "",
"scripts": {
"start": "react-app-rewired start",
"stop": "taskkill -F -IM node.exe",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject",
"prettier": "prettier --write ./src/**/**/**/*"
},
"dependencies": {
"#babel/runtime": "7.0.0-beta.55",
"#material-ui/core": "^1.5.1",
"#material-ui/icons": "^2.0.2",
"#material-ui/lab": "^1.0.0-alpha.10",
"axios": "^0.19.2",
"classnames": "^2.2.6",
"core-js": "^2.5.7",
"date-fns": "2.0.0-alpha.7",
"downshift": "^2.1.1",
"echarts": "^4.1.0",
"echarts-for-react": "^2.0.14",
"element-resize-event": "^2.0.9",
"font-awesome": "~4.7.0",
"history": "^4.6.1",
"jquery": "^3.4.1",
"jquery-slimscroll": "~1.3.8",
"material-ui-pickers": "1.0.0-rc.11",
"prop-types": "^15.6.2",
"rc-queue-anim": "^1.6.5",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-hot-loader": "^4.3.4",
"react-loadable": "^5.5.0",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "5.0.0-alpha.6",
"react-scripts": "2.0.0-next.3e165448",
"redux": "^4.0.0",
"redux-immutable-state-invariant": "^2.1.0",
"redux-thunk": "^2.3.0"
},
"browserslist": {
"development": [
"last 2 chrome versions",
"last 2 firefox versions",
"last 2 edge versions"
],
"production": [
">0.25%",
"not op_mini all",
"ie 11"
]
},
"devDependencies": {
"bootstrap": "^4.4.1",
"node-sass": "^4.13.1",
"prettier": "^1.14.2",
"react-app-rewire-provide-plugin": "^1.0.0",
"react-app-rewired": "^1.5.2",
"sass-loader": "^7.0.1"
}
}
Please help, I'm an intern at work and this is the first project I've gotten and I don't want to mess it up.
VS Code auto imported TRUE from node-sass while I was typing thus adding import {TRUE} from 'node-sass' in the file, which resulted in this error.
Removing it fixed the issue.
VS Code auto-imported Null just like #SadAzzi Answer, Removing it everything worked like a charm for me.
import { NULL } from "node-sass";
Node-sass is a native C++ module and can't be run in the browser. It's possible dart-sass might, but I've never tried
I had this same exact problem. For some reason, import {TRUE} from 'node-sass was imported (not by me). The steps I took to resolve this was to uninstall SCSS, SASS Loader, and get rid of that aforementioned import. I am not sure if this would help, but I wanted to post this because I have been researching this error for the past two days.
You need to find and remove the following line from your code, probably it's been imported by accident by your IDE. Most likely that is the problem
import { render } from 'node-sass';
I am trying to leverage React-native-vecor-icons package in a project that uses Server-Side-Rendering react deployment (SSR).
React-native-vector-icons works fine in standard web deployments as well (not just in react-native on mobile). HOwever with Server-side-rendering there is a problem.
The package author, chose to publish his library into NPM repository with ES6 syntax for modules (eg import ... }.
While web-browsers rely on transply by babel to ES5, during app build stage -- this does not help with server side deployment. Because it is the server (NodeJs) that needs to be able to understand the package syntax.
This is, I believe, why I am getting this error.
If my understanding of the problem is correct, then I need to figure out a way to get Babel to transply this offending package on the fly and to feed it into node-js at run time.
This is where I need help, simply setting various stuff at .babelrc is not helping (see below). And I do not know how to make this work without making manual changes to the React-native-vector icons code (See at the end the manual changes I that I figured out to make... to test out the theory).
The error:
c:\Users\v\home\devel\mine\ltproject\mob\rnweb\aa1a\ssr-aft\node_modules\react-native-vector-icons\Ionicons.js:6
import createIconSet from './lib/create-icon-set';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:152:10)
at Module._compile (module.js:605:28)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at Object.react-native-vector-icons/Ionicons (c:\Users\v\home\devel\mine\ltproject\mob\rnweb\aa1a\ssr-aft\build\server.js:1527:18)
The piece of code from React Native Vector Icons library within node_modules, that's causing the problem (first import statement)
/**
* Ionicons icon set component.
* Usage: <Ionicons name="icon-name" size={20} color="#4F8EF7" />
*/
import createIconSet from './lib/create-icon-set';
import glyphMap from './glyphmaps/Ionicons.json';
const iconSet = createIconSet(glyphMap, 'Ionicons', 'Ionicons.ttf');
export default iconSet;
export const Button = iconSet.Button;
export const TabBarItem = iconSet.TabBarItem;
export const TabBarItemIOS = iconSet.TabBarItemIOS;
export const ToolbarAndroid = iconSet.ToolbarAndroid;
export const getImageSource = iconSet.getImageSource;
My package.json
{
"name": "aa1a",
"version": "0.0.1",
"license": "XYZ",
"private": true,
"scripts": {
"start": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"start:prod": "NODE_ENV=production node build/server.js",
"vclient": "webpack --watch --progress"
},
"dependencies": {
"#jaredpalmer/after": "latest",
"airbnb-browser-shims": "^2.1.0",
"bootstrap": "^3.3.7",
"bundle-loader": "^0.5.6",
"compression": "^1.7.2",
"express": "^4.16.2",
"postcss-syntax": "^0.10",
"prop-types": "^15.6.1",
"pubsub-js": "^1.6",
"qs": "^6.5.2",
"razzle": "^2.0.0-alpha.12",
"react": "^16.3.2",
"react-art": "^16.3.2",
"react-bootstrap": "^0.32.1",
"react-dom": "^16.3.2",
"react-helmet": "^5.2.0",
"react-markdown": "^3.3.2",
"react-native-vector-icons": "^4.6.0",
"react-native-web": "^0.6.1",
"react-router-dom": "^4.3.0-rc.2",
"react-virtualized": "^9.19",
"react-virtualized-image-measurer": "^0.3",
"resize-observer-polyfill": "^1.5.0",
"serialize-javascript": "^1.4.0",
"tree-model": "^1.0.6",
"webpack-visualizer-plugin": "^0.1.11"
},
"devDependencies": {
"babel-plugin-react-native-web": "^0.7.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-preset-react-native": "^4.0.0",
"babel-register": "^6.26.0",
"mini-css-extract-plugin": "^0.4.0",
"node-sass": "^4.8.3",
"sass-loader": "^6.0.7",
"stylelint": "^9.2.1",
"stylelint-config-standard": "^18.2.0",
"treeify": "^1.1.0",
"webpack-bundle-analyzer": "^2.9.1"
}
}
I had also tried to tell babel-loader to transply into ES5 syntax compatible with node version ( (I am running node 9.10)). But installing babel-preset-env #1.3.3 (because that's what razzle/babel is using)). And, then, modifying my .babelrc with
{
"presets": ["razzle/babel",
"react-native",
[
"babel-preset-env",
{
"targets": {
"node": 9,
"esmodules": true
}
}
]
],
"plugins": ["react-native-web",
"transform-es2015-modules-commonjs",
"transform-class-properties"
]
}
That, unfortunately, did not help -- getting same error.
I also tried upgrading to node v10.2 and using
npm start -- --experimental-modules
... razzle start "--experimental-modules"
Did not work either.. although I am not 100% sure if razzle, in this case is passing the command line arg into node.js
As noted, above -- I figured out the manual code changes I need to make to get RN vector icons to start up under Node JS (I am using version 9.1)
Change 1) CD to node_modules/react-native-vector-icons. Copy Ionicons.js into Ionicons_org.js.
Change 2) Replace the Ionicons.js with this code (and delete the rest).
require('babel-register')({
plugins: ["transform-class-properties","react-native-web"],
presets: [ 'env' ],
// Ignore everything in node_modules except node_modules/react-native-vector-icons
ignore: /node_modules\/(?!react-native-vector-icons)/
})
// Import the rest of our application.
module.exports = require('./Ionicons_org.js')