Skip to content
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

Make compatible for web #9

Open
otim opened this issue May 6, 2022 · 13 comments
Open

Make compatible for web #9

otim opened this issue May 6, 2022 · 13 comments
Assignees
Labels
enhancement New feature or request

Comments

@otim
Copy link

otim commented May 6, 2022

Is your feature request related to a problem? Please describe.
I am working on a react-native-web project. When I naively tried to use this module inside my project I was getting the error:
Support for the experimental syntax 'jsx' isn't currently enabled

Describe the solution you'd like
I think this module is just missing the proper configuration to be used for react-native / react-native-web or classic react

Describe alternatives you've considered
Modules targeted for react web rely on things on window and/or document calls. These are not available in react native as far as I know.

Additional context
I have tried to come up with a way to compile this module to be used for web. However, I am really lacking the basics here. Nonetheless, if it helps, have a look at my attempt here: https://github.com/otim/matomo-tracker-react-native/tree/feature/react_native_web

@otim otim added the enhancement New feature or request label May 6, 2022
@donni106
Copy link
Owner

Hi @otim, interesting topic. I never did some work "for" react-native-web yet, just used it in some cases. The projects i use matomo-tracker-react-native in are "app only". Making this package work for react-native-web should work, as there is nothing really special "native". We use hooks and fetches at the end. I would setup a basic react native project in the following days with react-native-web enabled, install the package, wrap the main app container to fire a trackAppStart and see what happens. I hope it brings more clarity.

@otim
Copy link
Author

otim commented May 12, 2022

Hi @donni106! Thanks for your reply and sharing your thoughts!
Now that I thought more about it, I think it's not necessarily specific to react-native-web. It might be easier (and sufficient) to reproduce this in a pure react (web) project.
I was able to make this work by copying the source files into my project. I know this is not the clean way to do it but I lost patience and to me it proved that there is nothing in the way to make this work for web.
Thanks a lot for looking into it! If there is anything I can help you with, please let me know 🙌

@donni106
Copy link
Owner

good infos and well done 👍
but i still want to address this and keep it on my map. i will come back to you for anything, thanks.

@nickvanboven
Copy link

nickvanboven commented Oct 28, 2022

Any update on this, or is there a easy way to exclude the tracking for web. We have an app which is for ios/android and web. Tracking in ios and android works but web wont build. For us it not required that web also support tracking but would be nice if it would build

@donni106
Copy link
Owner

Hi @nickvanboven

web wont build

can you elaborate a bit? What are you running and what is the failing outcome? Are there logs you can share?

@nickvanboven
Copy link

@donni106 Yes of course, will provide some information this afternoon

@nickvanboven
Copy link

nickvanboven commented Nov 2, 2022

@donni106 When running expo start, and starting the web browser we recieve the following error
Screenshot from 2022-11-02 07-59-52

@donni106
Copy link
Owner

donni106 commented Nov 10, 2022

@nickvanboven I was able to reproduce the same error. My research shows up some webpack/babel topics. Can you show you config files used in the project? Which expo version are you using?
The following issue seems to be appropriate, although unfortunately not clearly solved: expo/expo#16673

@donni106
Copy link
Owner

donni106 commented Nov 10, 2022

I played around with webpack custom configs but without success. There is a way to merge custom configs in expo webpack configs (webpack.config.js) in the following way:

const { merge } = require('webpack-merge');
const createExpoWebpackConfigAsync = require('@expo/webpack-config');

const matomoTrackerConfiguration = {
  test: /.*matomo-tracker-react-native.*\.(mjs|[jt]sx?)$/,
  use: {
    loader: 'babel-loader'
  }
};

// Expo expects a function so we can pass around options.
module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  return merge(config, {
    module: {
      rules: [matomoTrackerConfiguration]
    }
  });
};

But as I do not understand the problem exactly at transpiling or something, I could not figure out a correct working custom config yet.

image

Any ideas?

@otim
Copy link
Author

otim commented Nov 10, 2022

Sorry, I don't fully understand where you are going with the expo config. For completeness, I am not using expo for my react native build.

If I remember correctly, what I concluded was that there is a fundamental difference between how react native and react web projects are built. For react native, dependencies (node_modules) are built from source. This might be done by running pod update (for ios) but I am not sure. React web on the otherhand seems to expect dependencies to be pre-compiled and bundled in some specific way. I guess this needs to be done before or during publishing to npm.

It's been a while that I looked into this issue, so I might be mixing up things. Also, I am far from being an expert in all these topics, so I might be using wrong terminology here and there. Sorry about that

@donni106
Copy link
Owner

donni106 commented Dec 8, 2022

I guess this needs to be done before or during publishing to npm.

This is something I would need to look up first, never done that before. But it is a good hint, thanks @otim.

@uzun0ff
Copy link

uzun0ff commented Dec 12, 2022

I played around with webpack custom configs but without success. There is a way to merge custom configs in expo webpack configs (webpack.config.js) in the following way:

const { merge } = require('webpack-merge');
const createExpoWebpackConfigAsync = require('@expo/webpack-config');

const matomoTrackerConfiguration = {
  test: /.*matomo-tracker-react-native.*\.(mjs|[jt]sx?)$/,
  use: {
    loader: 'babel-loader'
  }
};

// Expo expects a function so we can pass around options.
module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  return merge(config, {
    module: {
      rules: [matomoTrackerConfiguration]
    }
  });
};

But as I do not understand the problem exactly at transpiling or something, I could not figure out a correct working custom config yet.

image

Any ideas?

Had the same issue, what fixed it for me was similar to this but had to add the node modules to the config path.

const { merge } = require('webpack-merge');
const createExpoWebpackConfigAsync = require('@expo/webpack-config');

const matomoTrackerConfiguration = {
  test: /node_modules\/matomo-tracker-react-native\/src\/[a-zA-Z]+\.js/,
  use: {
    loader: 'babel-loader'
  }
};

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  return merge(config, {
    module: {
      rules: [matomoTrackerConfiguration]
    }
  });
};

@donni106 donni106 changed the title make compatible for web Make compatible for web Mar 28, 2023
@donni106 donni106 added this to the 0.3.1 milestone Mar 28, 2023
@donni106
Copy link
Owner

Coming back to this, I achieved running it a few more steps further with:

const { merge } = require('webpack-merge');
const createExpoWebpackConfigAsync = require('@expo/webpack-config');

const matomoTrackerConfiguration = {
  test: /node_modules\/matomo-tracker-react-native\/src\*.(mjs|[jt]sx?)$/,
  use: {
    loader: 'babel-loader'
  }
};

// Expo expects a function so we can pass around options.
module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);

  return merge(config, {
    module: {
      rules: [matomoTrackerConfiguration]
    }
  });
};

The error now says:
image

@donni106 donni106 removed this from the 0.3.1 milestone Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants