Giter VIP home page Giter VIP logo

create-express-react's Introduction

Hey there ๐Ÿ‘‹

  • ๐Ÿ™Š Friends prefer call me H here.
  • ๐Ÿ’ป I write code for Javascript infra/tooling, audio processing, and music.
  • ๐Ÿ•น I use neovim.
  • ๐ŸŽธ I play guitar on my Youtube channel,
  • ๐ŸŽค I have a studio doing recording/mixing/music production.
  • ๐Ÿค˜๐Ÿผ I like metal, especially 80's thrash and modern progressive.
  • ๐Ÿ‹๐Ÿป I spend ~2 hours on weight lifting/jumping rope/burpee/basketball everyday.

create-express-react's People

Contributors

haochuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mahmoudalawdh

create-express-react's Issues

ServiceWorker registration error via Express wildcard (*) route

In app.js, there is one wildcard (asterisk / *) route that redirects to index.html for production environments:

// Load React App
// Serve HTML file for production
if (env.name === "production") {
  app.get("*", function response(req, res) {
    res.sendFile(path.join(__dirname, "public", "index.html"));
  });
}

Unfortunately, this means when the browser tries to load create-react-app's pre-configured ServiceWorker at public/service-worker.js, it initially gets routed through this wildcard route and gets sent to the browser with the incorrect MIME type of text/html in its http headers, resulting in this console error:

Error during service worker registration: DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').

The solution I found is to add an additional route before the wildcard route for service-worker.js:

if (env.name === "production") {
  app.get("/service-worker.js", (req, res) => {
    res.sendFile(path.resolve(__dirname, "public", "service-worker.js"));
  });
  app.get("*", function response(req, res) {
    res.sendFile(path.join(__dirname, "public", "index.html"));
  });
}

@haochuan, if you're OK with this solution, I will gladly create a pull request for it.

Server files transpiled by Babel do not run (import statements not natively supported by Node)

There is no transpilation preset defined in either the npm script buildServer, or in a .babelrc file, so Babel doesn't actually do any transpilation of the built files that get produced in the dist folder.

As a result, I immediately get an error on the first line of dist/index.js because import statements are not natively supported (yet) by nodejs.

Unfortunately, I am also having issues when I create a .babelrc file with presets that should work, like:

{
  "presets": ["es2015"]
}

The first error I get is related to the server/config/env.js file; it doesn't seem to import correctly:

if (_env2.default.name === "production") {
              ^

TypeError: Cannot read property 'name' of undefined
    at Object.<anonymous> (/Users/msidor/Documents/fmeco/ceed/dist/app.js:80:19)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/msidor/Documents/fmeco/ceed/dist/index.js:7:12)
    at Module._compile (module.js:635:30)

I'm inexperienced with Babel, so I could use some help to figure out the correct configuration for this repository.

@haochuan, have you been able to get the build script to run correctly on your machine?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.