Giter VIP home page Giter VIP logo

Comments (5)

catamphetamine avatar catamphetamine commented on May 23, 2024

Your webpack treats SVG files differently hence the error.
Configure your SVG file loading properly.
Example of React SVG loading:
https://github.com/catamphetamine/webpack-isomorphic-tools#svg-react-loader-css-stylesheets-with-css-modules-feature

from webpack-isomorphic-tools.

catamphetamine avatar catamphetamine commented on May 23, 2024

from webpack-isomorphic-tools.

egorovli avatar egorovli commented on May 23, 2024

Thanks. I know it may seem like an error in webpack config, but if you look in the files in the gist webpack is configured properly:

{
  test: webpackIsomorphicToolsPlugin.regularExpression('files'),
  include: /src\/files/,
  loader: 'file-loader',
  options: {
    name: env.dev ? '[path][name].[ext]' : 'assets/[hash:12].[ext]'
  }
}

if I console.log it I get:

{
  test: /\.(png|jpg|gif|ico|svg|xml|json)$/,
  include: /src\/files/,
  loader: 'file-loader',
  options: {
    name: '[path][name].[ext]'
  }
}

isomorphic config has correct extensions, too:

module.exports = env => ({
  webpack_assets_file_path: env.dev
    ? '../webpack.assets.json'
    : '../dist/webpack-assets.json',
  debug: true,
  assets: {
    files: {
      extensions: [
        'png',
        'jpg',
        'gif',
        'ico',
        'svg',
        'xml',
        'json'
      ],
      include: [
        /src\/files/
      ]
    }
  }
})

and in the assets the .svg file is correctly resolved:

"./files/icons/down.svg": "http://localhost:8081/files/icons/down.svg"

it also appears in the stats:

{
  "name": "files/icons/down.svg",
  "size": 875,
  "chunks": [],
  "chunkNames": [],
  "emitted": false
}

The same thing happens to any file, not just svgs:

[webpack-isomorphic-tools] [debug] require() called for /Users/egorovli/Dev/project/src/files/images/cover.jpg
[webpack-isomorphic-tools] [debug]  skipping require call for ./files/images/cover.jpg
[require-hacker] [debug] Fallback to original loader
/Users/egorovli/Dev/project/src/files/images/cover.jpg:1
(function (exports, require, module, __filename, __dirname) { ����
                                                              ^

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:152:10)
    at Module._compile (module.js:605:28)
    at Module._extensions..js (module.js:652:10)
    at newLoader (/Users/egorovli/Dev/project/node_modules/pirates/lib/index.js:96:7)
    at Object._module2.default._extensions.(anonymous function) [as .jpg] (/Users/egorovli/Dev/project/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:293:60)
    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.<anonymous> (/Users/egorovli/Dev/project/src/client/components/Landing/index.jsx:7:1)
    at Module._compile (module.js:641:30)
    at Module._compile (/Users/egorovli/Dev/project/node_modules/pirates/lib/index.js:91:24)
    at Module._extensions..js (module.js:652:10)
    at Object.newLoader [as .jsx] (/Users/egorovli/Dev/project/node_modules/pirates/lib/index.js:96:7)
[nodemon] app crashed - waiting for file changes before starting...

😞

from webpack-isomorphic-tools.

egorovli avatar egorovli commented on May 23, 2024

Ok, I think I've found the culprit here, if I remove

include: [
  /src\/files/
]

from isomorphic config, everything works. Since I guess the relative path gets tested (./files/images/cover.jpg), not the absolute one. I replaced it with:

include: [
  /\.\/files/
]

from webpack-isomorphic-tools.

catamphetamine avatar catamphetamine commented on May 23, 2024

from webpack-isomorphic-tools.

Related Issues (20)

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.