Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Unable to require tag on server side in Riot JS

When I declare: require('./public_html/Tags/blog_post_details.tag'), I get the following error:

E:\WORKSPACE\NETBEANS_WORKSPACE\MyProject\public_html\Tags\blog_post_details.tag:1
(function (exports, require, module, __filename, __dirname) { <blog_post_details >
                                                              ^

SyntaxError: Unexpected token <
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (E:\WORKSPACE\NETBEANS_WORKSPACE\MyProject\server.js:7:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

The path is correct because this line works var commonsFile = require('./public_html/Tags/commons.json');

WebPack config file:

var path = require('path');
var webpack = require('webpack');
module.exports = {
    entry: './index.js',
    output: {
        path: __dirname,
        filename: 'public_html/assets/js/bundle.js'
    },
    resolveLoader: {
        root: path.join(__dirname, 'node_modules')
    },

    module: {
        preLoaders: [{
            test: /\.tag$/,
            exclude: /node_modules/,
            loader: 'riotjs-loader',
            query: {
                //type: 'none'
                //compact: true
            }
        }],
        loaders: [
            /*{
                test: /\.tag$/,
                loader: 'tag',
                exclude: /node_modules/
            },*/
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    //commenting because of this issue https://github.com/mapbox/mapbox-gl-js/issues/3422
                   // presets: ['es2015']
                }
            }
        ]
    },
    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.ProvidePlugin({
            riot: 'riot'
        })
    ]
};
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The node require function only recognizes files ending in .js for Javascript files, .json for JSON files, and .node for binary extensions to the Node runtime. In the case of Javascript files, you can omit the trailing .js if the file or module can be found by Node's module system (i.e. under node_modules).

From your example, it appears that you are attempting to use require from client-side code. Unless you use browserify, webpack or another client-side bundler which provide their own client-side version of require, you cannot use it.

As noted in my comment below, the video link you provide shows client-side code loading tag files via webpack. You'll need to check webpack's config to assure it is properly bundling your tag files for delivery to the browser. Again from the video, the example code is loading its tag file from ./tags/filename.tag where the root of that path is defined by webpack.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda