I have setup the fastify framework with fastify-cli library with command fastify-cli generate. It has fastify-autoload plugin used out of the box.
But, it will throw an error when I add my own service with exception for model.js and schema.js files.
...
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'services'),
options: Object.assign({}, opts),
ignorePattern: /.*(model|schema)\.js/
})
...
Error message:
assert.js:788
throw newErr;
^
AssertionError [ERR_ASSERTION]: ifError got unwanted exception: plugin must be a function
at wrap (D:\project\kuisioner\backend\node_modules\fastify-cli\start.js:124:5)
...
actual: Error: plugin must be a function
...
error Command failed with exit code 1.
...
But it will run smoothly when I register it manually
...
fastify.register(require('./services/quiz/get'))
fastify.register(require('./services/quiz/post'))
...
My file structure:
- src
- plugins
- db.js
- services
| - quiz
| - get.js
| - model.js
| - post.js
| - schema.js
- app.js
I use fastify-cli fastify start -l info src/app.js to run my code
Here's my repo https://github.com/nnfans/kuisionerid_backend
Checking your repo the error is the dir value. You must point to the dir with the files, it is not supported the recursive loading yet
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'services/quiz'),
options: Object.assign({}, opts),
ignorePattern: /.*(model|schema)\.js/
})
With this change, the npm start will work.
Another option is to use module.exports.autoload = false in the files that need to be skipped, but your regex is ok.
if you got here and you use typescript, maybe try to delete the dist dir and re-run tsc, you might have had a bad route that persisted there
Related
I'm trying to make a program that needs to check if a folder exists. If it does - it deletes and creates it again (to clear it). If it doesn't - it creates it. After that I copy all paths that get returned from a function into that cleared folder. I'm currently running into errors for permssions to delete the folder and also errors for copying the file. I tried chmodSync but I couldn't work it out. Here's my code:
function sortTracks(dir) {
fs.chmodSync(
path.join(dir, "playlist"),
fs.constants.S_IRUSR | fs.constants.S_IWUSR
);
if (fs.existsSync(path.join(dir, "playlist")))
fs.rmdirSync(path.join(dir, "playlist"));
fs.mkdirSync(path.join(dir, "playlist"));
fs.chmodSync(
path.join(dir, "playlist"),
fs.constants.S_IRUSR | fs.constants.S_IWUSR
);
getAllFiles(dir, []).forEach(track => {
fs.chmodSync(track, fs.constants.S_IRUSR);
fs.copyFileSync(track, path.join(dir, "playlist"));
});
}
From what I could tell, sortTracks attempts to:
Set the permissions of ${cwd}/playlist to be readable and writeable by the user
Remove ${dir}/playlist if it already exists
Create the ${dir}/playlist directory
Set the permissions of ${dir}/playlist, as done in step #2
For each file returned by getAllFiles(dir, []):
Set its permissions to be readable by the user
Copy it to ${dir}/playlist
A few things that stood out to me:
Step #1 is redundant. You can see it for yourself - try running the following in bash:
$ mkdir a
$ chmod -rw a
$ rm -rf a
You'll see that a gets created and removed.
Step #4 is redundant. The default permissions for a directory make it readable & writeable.
Removing the directory should be done using:
fs.rmSync(path.join(dir, "playlist"), {recursive: true, force: true});
Instead of fs.rmdirSync (see the docs).
I hope fixing these will resolve the issue for you.
[12:20:17] Finished 'images' after 12 s
Error from uglify in compress task Error in plugin 'gulp-uglify'
Message:
D:\projects\Source\app\scripts\vendor.js: SyntaxError: Unexpected token: keyword (default)
Details:
fileName: D:\projects\Source\app\scripts\vendor.js
lineNumber: 96908
[12:23:39] Finished 'fonts' after 3.55 min
[12:23:49] Finished 'jshint' after 3.75 min
I am getting above error on gulp Build. so far i have tried all solutions of GulpUglifyError:Unable to minify JavaScript to no success. any ideas?
Follow this example with uglifyes or use Babel or (if you use it) TypeScript to output to ES5.
Make sure to read the documentation more closely.
Example:
var uglifyes = require('uglify-es'); // for ES support
var composer = require('gulp-uglify/composer'); // for using a different uglify runtime/config
var uglify = composer(uglifyes, console); // setup the new uglify constant
function javascriptTask ( done ) {
gulp.src("[[file location]]")
// [pipe processing]
.pipe(uglify())
done(); // this tells Gulp 4 that the task is done
}
let main = gulp.[series | parallel](javascriptTask); // edit out series or parallel depending on needs
export default = main // allows you launch all tasks in the gulp.[series | parallel] from the terminal with gulp
You can also use gulp-terser
For transpiling
For a babel solution: click here
If you use TypeScript you should have target : 'es5' in your .tsconfig, tsify (for browserify) or gulp-typescript object.
I am trying to implement something simple: I want my e2e tests run with Cypress and cucumber.
I have an application created with Vue CLI 4.1.1. I added with NPM the package: cypress-cucumber-preprocessor (V1.19.0)
Edit:
After a lot of research and tests, I think I found where the problem comes from, but I don't know how to fix it yet:
The '#vue/cli-plugin-babel/preset' does not seem to be working with
.feature file...
My babel.config.js file is:
module.exports = {
presets: [
'#vue/cli-plugin-babel/preset'
]
}
Any idea how I can make cli-plugin-babel working with cucumber cypress?
Original message :
I have a Test.feature file, executing steps defined in test.step.js files.
Here is the content of my test.spec.js
import { When, Then } from 'cypress-cucumber-preprocessor/steps';
import { HomePage } from './pages/home.page';
When(/^I open the Home page$/, () => {
let homePage = new HomePage();
homePage.goTo();
});
Then(/^I see "([^"]*)" in the main heading$/, msg => {
cy.contains('h1', msg)
});
And the content of my PageObject home.page.js:
export class HomePage {
goTo() {
cy.visit("/");
}
}
When I run:
npm run test:e2e
I get the following error:
Oops...we found an error preparing this test file:
tests/e2e/features/Test.feature
The error was:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
These errors does not occur when I use:
export function goToHomePage() {
cy.visit("/");
}
You can checkout my project on Github: https://github.com/truar/cloudcmr-v2 (branch master for the passing case, branch pageObject_pattern for the failing case).
I am assuming this is something related to ES6 and cypress... but I clearly don't know what is going on here. Besides, everything I find on the Internet talks about cypress cucumber and Typescript, which I don't use...
What am I missing?
I found the answer. See this PR for more details : https://github.com/cypress-io/cypress/issues/2945
Basically, there is an incompatibility between Babel 7 and Cypress 3. I had to change the babel.config.js file :
module.exports = process.env.CYPRESS_ENV
? {}
: {
presets: ["#vue/cli-plugin-babel/preset"]
};
It is just a workaround, not a real fix. We have to disable babel when running cypress.
Hope will help you !
I am trying to use Yjs with React. Everything works perfectly except it cannot npm run build. The error it is giving me is that static/js/main.499b0481.js from UglifyJs and SyntaxError: Unexpected token: name (requireModule) [./~/yjs/src/y.js:66,0]. So here is the problem, what is inside y.js line 66 is let requireModule = {} which is an expression Uglify can't parse. I wonder how can I specify that for this node module, I want to build it with Babel instead of Uglify. Actually I couldn't find what caused it to be built using Uglify. I tried to add include: [/node_modules\/yjs/], to my webpack.config but it didn't change anything. Any good ideas?
I actually found this code inside their npm package
gulp.task('dist:es6', function () {
return (browserify({
entries: files.dist,
debug: true,
standalone: options.moduleName
}).bundle()
.pipe(source(options.targetName))
.pipe(buffer())
.pipe($.sourcemaps.init({loadMaps: true}))
// .pipe($.uglify()) -- generators not yet supported see #448
.pipe($.rename({
extname: '.es6'
}))
.pipe(header(banner, { pkg: require('./package.json') }))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./dist/')))
})
But somehow it had zero effect in the build process
Context
I have a few grunt tasks that I've already written, and I'd like to use them with a new project I'm writing in Sails.js.
With Sails.js, you can add additional grunt tasks by adding a JS file to the /tasks/register folder. Before we get to the file I've added, let's talk about the problem.
The Problem
Sails won't lift. Debugger shows:
debug: --------------------------------------------------------
error: ** Grunt :: An error occurred. **
error:
------------------------------------------------------------------------
ERROR
>> Unable to process task.
Warning: Required config property "clean.dev" missing.
The issue in question is obviously with grunt, so then I try grunt build (which automatically runs with sails lift):
Running "clean:dev" (clean) task
Verifying property clean.dev exists in config...ERROR
>> Unable to process task.
Warning: Required config property "clean.dev" missing. Use --force to continue.
From this, I've garnered that this is a path issue. Let's take a look at the file I've added.
/tasks/register/customTask.js
The task here loads load-grunt-config, which is the source of my problems:
module.exports = function(grunt) {
// measures the time each task takes
require('time-grunt')(grunt);
// This require statement below causes my issue
require('load-grunt-config')(grunt, {
config: '../../package.json',
scope: 'devDependencies',
overridePath: require('path').join(process.cwd(), '/asset-library/grunt')
});
grunt.registerTask('customTask', [
'newer:jshint',
'newer:qunit',
'newer:concat',
'newer:cssmin',
'newer:uglify'
]);
};
I had assumed that using overridePath instead of configPath would solve my issue, but alas, it's not quite that simple. Is there some way to make it so that I can use my own custom tasks folder with load-grunt-config like I've done in other projects, or is there some magic conditional I can wrap the require statement around?
I only need it to run with grunt customTask, and not run with grunt * (anything else).
Okay, this was actually pretty easy. All I had to do was change the grunt.registerTask call in my customTask.js file from this:
grunt.registerTask('customTask', [
'newer:jshint',
'newer:qunit',
'newer:concat',
'newer:cssmin',
'newer:uglify'
]);
to this:
grunt.registerTask('customTask', 'My custom tasks', function() {
// The require statement is only run with "grunt customTask" now!
require('load-grunt-config')(grunt, {
config: '../../package.json',
scope: 'devDependencies',
overridePath: require('path').join(process.cwd(), '/asset-library/grunt')
});
grunt.task.run([
'newer:jshint',
'newer:qunit',
'newer:concat',
'newer:cssmin',
'newer:uglify'
]);
});
In case it's not clear, I did have to move the require('load-grunt-config') call, so if you're copy + pasting, make sure to remove the require statement that's outside the grunt.registerTask call.
You can find more information about custom Grunt tasks here.