Search code examples
reactjsdockertailwind-cssvite

Error: Docker container with react, vite and tailwindcss, getting error Unexpected token 'export'


I am busy setting up a project where I want to use Docker with react, vite and tailwinds. With docker I get the following error trying to install tailwind

error message: docker /app/postcss.config.cjs:1 export default { ^^^^^^ SyntaxError: Unexpected token 'export'`

or: previous error

error message: docker docker vite Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'tailwindcss' imported from /app/vite.config.js

Currently the setting are working when I run the project without docker. it works fine

github: https://github.com/xxxx/xxxx

I have been looking for solution online for a couple of days unfortunatly with no succes. Trying out several configuration settings from different blogs. Unfortunatley with little success.

I expect my project to work with a docker container, and use tailwinds with no problems


Solution

  • The code in your current repository builds and runs fine for me.

    docker-compose build && docker-compose up
    

    However, I could not access the site via port 5173. To get this to work I made a change to package.json, specifying 0.0.0.0 as the host for the dev script:

      "scripts": {
        "dev": "vite --host 0.0.0.0",
        "build": "vite build",
        "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
        "preview": "vite preview"
      },
    

    enter image description here