Fatal error: spawn ENOENT - phantomjs

Gruntfile.js content:
grunt.initConfig({
connect: {
server: {
options: {
port: 5005,
base: '.'
}
}
},
qunit: {
all: ['test/*.html']
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.registerTask('test', ['connect', 'qunit']);
Test/index.html file content:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Sitejson - QUnit Test Runner
</title>
<link rel="stylesheet" href="libs/qunit/qunit.css" type="text/css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="libs/qunit/qunit.js" type="text/javascript"></script>
<script src="testcases/tests.js" type="text/javascript"></script>
</body>
</html>
tests.js content:
QUnit.test("hello test", function(assert) {
assert.ok(1 == "1", "Passed!");
});
I am working on Ubuntu / Linux environment. I have also installed Phantomjs and is working fine. Whenever i try to run grunt test I'm receiving a fatal error: spawn ENOENT error.
whereas i try running it on browser its qunit is working fine...
I am not able to identify what the issues. Am i missing some more configuration over here.
grunt test --debug shows me:
Running "connect:server" (connect) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-connect/tasks/connect.js
Started connect web server on http://0.0.0.0:5005
Running "qunit:all" (qunit) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/tasks/qunit.js
Testing test/index.html [D] ["/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/phantomjs/main.js","/tmp/1405775714604.2773","test/index.html","{\"timeout\":5000,\"inject\":\"/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/phantomjs/bridge.js\",\"urls\":[],\"force\":false,\"console\":true,\"httpBase\":false}"]
Fatal error: spawn EACCES

Use the following process:
set the tmpdir environment variable:
setenv TMPDIR=~/tmp
Rerun the grunt task
If it works, set this permanently by adding the following to your .bashrc or .profile:
export TMPDIR=~/tmp
References
Troubleshooting · npm/npm Wiki
Secure Programs HowTo
Environment Variables
FAQ Troubleshooting

Related

How to config Vite build output that can run with <script type="text/javascript"></script>

How can I config Vite build to output with script type="text/javascript"
I'm using Vite 2.7.2, when finished building the code in HTML output the script tag as follow
<script type="module" crossorigin src="/assets/index.0c37d7b4.js"></script>
What I want is
<script type="text/javascript" crossorigin src="/assets/index.0c37d7b4.js"></script>
The code run fine with type="module" but when I manually replace it with type="text/javascript" the code break and output following error
Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
Here is the original code before building
const elements = {
root: document.querySelector('#root'),
};
elements.root.innerHTML = `Loading...`;
The reason I want the type to be type="text/javascript" because Shopify platform only accept script with type "text/javascript"

Vue.js - How to insert dollar$ sign into main index.html file

I have the main index.html of my application.
When I try to build it, I get an error:
ERROR Build failed with errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! axeleron#0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 1
This error appears because there is a dollar $ sign in my index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<div id="app"></div>
<input value="${name}"/>
</body>
</html>
The question is: how to make sure that the error does not occur?
The problem is not dollar sign but the exact ${name} string that follows ES template literal syntax. Vue CLI uses HtmlWebpackPlugin to process index.html, which uses Lodash template to interpolate environment variables in HTML templates. _.template supports ES template literal syntax, tries to interpolate ${name} and fails because no name was provided.
This behaviour is not directly configurable in Vue CLI, in order for template to not use ES template syntax, _.templateSettings.interpolate regex need to be changed. This needs to be done in vue.config.js on the exact lodash package copy that HtmlWebpackPlugin uses, as there can be multiple package copies.
A more simple way to prevent it from being processed is to separate the string, so it would interpolate to ${name}:
<input value="${'$'}{name}"/>
I don't clear about what you're trying to say but i can help with this question,
"Question: how to insert these parameters into the main index.html of the application?"
May be you can use java script and then with the help of that you can add parameters into "index.main" file in any input field or any other tag.
var TxtEle = document.getElementById('Txt');
var BtnEle = document.getElementById('Btn');
console.log(Txt);
BtnEle.addEventListener('click',() => {
TxtEle.name = TxtEle.value;
});
console.log(Txt);
<html>
<head>
<title>
Example...
</title>
</head>
<center>
<p>
Add Name Parameter...
</p>
<input type="txt" id="Txt">
<input type="submit" id="Btn">
</center>
</html>

npm http-server with header X-Content-Type-Options

Used
$ http-server --cors .
to serve the following that tried to access https://github.com/vuejs/vue/blob/dev/dist/vue.js
<!DOCTYPE html>
<html>
</head>
<body>
DEMO
</body>
<script src="https://github.com/vuejs/vue/blob/dev/dist/vue.js"></script>
</html>
However it posted the following error:
The resource from “https://github.com/vuejs/vue/blob/dev/dist/vue.js” was blocked
due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
How to fix it or make npm http-server have header X-Content-Type-Options?

TemplateDoesNotExist at / home.html

I am trying to get a template to be rendered under my templates folder. I believe I set my views correct, URL settings, and settings for to render the view. However, I keep getting the same error, where the template cannot be found. I keep thinking its a path issue but cant put my finger on the issue. I added my screens of different views of my code.
# In newword/newword/newword/views.py
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {})
# In newword/newword/newword/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ 'templates/home.html'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
# In newword/newword/newword/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),`enter code here`
]
# In newword/newword/newword/templates/home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body></body>
</html>
# Error Output
TemplateDoesNotExist at /
home.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.1.5
Exception Type: TemplateDoesNotExist
Exception Value:
home.html
Exception Location: /usr/local/lib/python3.7/site-packages/django/template/loader.py in get_template, line 19
Python Executable: /usr/local/opt/python/bin/python3.7
Python Version: 3.7.2
Python Path:
['/Users/robertromulus/pythonProjects/newword/newword',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
'/Users/robertromulus/Library/Python/3.7/lib/python/site-packages',
'/usr/local/lib/python3.7/site-packages']
Server time: Mon, 7 Jan 2019 03:02:48 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/robertromulus/pythonProjects/newword/newword/templates/home.html/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/admin/templates/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/auth/templates/home.html (Source does not exist)
Traceback Switch to copy-and-paste view
/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py in inner
response = get_response(request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/robertromulus/pythonProjects/newword/newword/newword/views.py in home
return render(request, 'home.html', {}) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/shortcuts.py in render
content = loader.render_to_string(template_name, context, request, using=using)
I want the home.html to be rendered when I go to the root path of the site.
Problem solved - I need to add another folder then templates, and under templates each html file. This video helped. https://www.youtube.com/watch?v=xp_N4JnxHIk&t=184s&list=PLhTjy8cBISEpXc-yjjSW90NgNyPYe7c9_&index=6

Trying to set up Grunt to automate some testing, testing works fine in the browser but not at the command line

I'm currently trying to incorporate GruntJS with a few plugins (PhantomJS Qunit and Connect plugins). However, setting up a simple test is throwing me errors and I can't find the solution despite a few days of searching. I'm using a local web server (MAMP) and the website is running on a CMS.
Running the tests by accessing the test template in a browser works fine, but when trying to access the same tools via the command line using sudo grunt test PhantomJS return an odd error:
Running "qunit:all" (qunit) task
Testing http://user-guides:80/test/test.html
Warning: PhantomJS timed out, possibly due to a missing QUnit start() call. Use --force to continue.
Aborted due to warnings.
Some of my searches had people downgrading their version of phantom.js to deal with similar problems, but so far none of those solutions have worked for me, and I'm afraid i'm missing something right in front of my face.
Here's the contents of my Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
hostname: 'user-guides',
port: 80,
base: 'public'
}
}
},
jshint: {
all: ['Gruntfile.js', 'public/assets/js/helper/*.js', 'public/assets/js/specific/*.js']
},
qunit: {
all: {
options: {
timeout: 5000,
urls: [
'http://user-guides:80/test/test.html',
]
}
}
}
}
);
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('test', ['connect', 'qunit']);
};
Here's the simple Qunit test
<html>
<head>
<meta charset="utf-8">
<title>Tests</title>
<link rel="stylesheet" href="/assets/lib/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="/assets/lib/qunit.js"></script>
<script>
console.log("====TEST===");
start();
test( "hello test", function() {
ok( 1 == "1", "Passed!" );
});
</script>
</body>
</html>
Any help is greatly appreciated.
In my test.html file I originally had just copied the example from the QUnit Cookbook
After finding a similar (possibly the same) issue here:
https://stackoverflow.com/a/25053808/1814739
I updated:
<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>
to:
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>
Running from command-line seems to work after adding http: to the src attribute.